2013年8月5日
摘要: 1 #include 2 int main() 3 { 4 int n; 5 while(scanf("%d",&n)!=EOF) 6 { 7 if(n%3==0) 8 printf("%d\n",n/3*2); 9 else if((n+1)%3==0)10 printf("%d\n",n/3*2+1);11 else printf("%d\n",n/3*2);12 }13 return 0;14 }muhaha 阅读全文
posted @ 2013-08-05 20:10 Ac_国士无双 阅读(157) 评论(0) 推荐(0) 编辑
  2013年7月29日
摘要: 按照开始时间做排序,不断更新在他之前的最大值,借此得出当前数据结束时间所能等到的最大值。 1 #include 2 #include 3 #include 4 using namespace std; 5 struct po 6 { 7 int s,e,p; 8 } a[100010]; 9 int cmp(po a,po b)10 {11 return a.smaxd)24 maxd=a[i].e;25 }26 sort(a,a+n,cmp);27 memset(maxsum,0,sizeof(maxsu... 阅读全文
posted @ 2013-07-29 20:21 Ac_国士无双 阅读(582) 评论(0) 推荐(0) 编辑
  2013年7月28日
摘要: 树状数组求逆序数,先排个序,从大到小往插,计算在他的前面有几个比他大,就是他的逆序数。(PS:最近对数量越来越不敏感了,老在这上面错。多做题,不能断啊) 1 #include 2 #include 3 #include 4 using namespace std; 5 typedef long long i64; 6 struct po 7 { 8 int num,ord; 9 } p[500050];10 int a[500050];11 template12 struct BIT {13 vector a;14 void init(int n) {15 ... 阅读全文
posted @ 2013-07-28 22:00 Ac_国士无双 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 题目大意很简单,按照命令连接节点,findset函数写的时候费了点劲儿,要注意那个累加距离值。其实因为刚开始学,还是对并查集的查询和连接不是很熟悉,多推几次就好了。 1 #include 2 #include 3 #include 4 using namespace std; 5 int set[20010],p[20010]; 6 int findset(int x) 7 { 8 int ans; 9 if(set[x]==x)10 return x;11 else12 {13 ans=findset(set[x]);14 ... 阅读全文
posted @ 2013-07-28 20:48 Ac_国士无双 阅读(286) 评论(0) 推荐(0) 编辑
  2013年7月27日
摘要: 基本上即使原来函数有的操作,更新和查询,sub的时候改成负数。 1 #include 2 #include 3 int c[1000005],n; 4 int lowbit(int x) 5 { 6 return x&(-x); 7 } 8 int sum(int x) 9 {10 int ret=0;11 while(x>0)12 {13 ret+=c[x];14 x-=lowbit(x);15 }16 return ret;17 }18 void add(int x,int d)19 {20 while... 阅读全文
posted @ 2013-07-27 20:25 Ac_国士无双 阅读(150) 评论(0) 推荐(0) 编辑
  2013年7月26日
摘要: 将边从小到大排序,然后从最小的开始枚举,判断连通,得到当前的速度最小差,比较得出最小值。 1 #include 2 #include 3 #include 4 using namespace std; 5 struct po 6 { 7 int u,v,w; 8 } s[1005]; 9 int p[1005];10 int cmp(po a,po b)11 {12 return a.w<b.w;13 }14 int findSet(int x)15 {16 if (p[x] == x)17 return x;18 return findSet(... 阅读全文
posted @ 2013-07-26 11:48 Ac_国士无双 阅读(226) 评论(0) 推荐(0) 编辑
摘要: 从小到大排序,判断连通。 1 #include 2 #include 3 #include 4 using namespace std; 5 int n,m,u[1000005],v[1000005],w[1000005],r[1000005],p[1005]; 6 int cmp(const int i,const int j) 7 { 8 return w[i]<w[j]; 9 }10 int find (int x)11 {12 if(p[x]==x)13 return x;14 else return p[x]=find(p[x]);15 }16 int... 阅读全文
posted @ 2013-07-26 11:44 Ac_国士无双 阅读(184) 评论(0) 推荐(0) 编辑
  2013年7月19日
摘要: 题目要求算出大小关系的所有情况,我们把相等的放在一起,他们之间没有大小关系,形成分组,这个就是由第二类斯特灵数算出来的,在对分好的组进行全排列。 1 #include 2 typedef long long i64; 3 int main() 4 { 5 int T,n; 6 i64 s[150][150],f[150]; 7 scanf("%d",&T); 8 f[0]=1; 9 for(int i=1;i<=100;i++)10 {11 s[i][i]=1;s[i][1]=1;f[i]=f[i-1]*i%20090126;12... 阅读全文
posted @ 2013-07-19 18:25 Ac_国士无双 阅读(234) 评论(0) 推荐(0) 编辑
摘要: 在钥匙与房间的所有情况中,我们知道当手中没有未开启的房间门的钥匙时我们需要破坏一扇门。在已开启的门中,钥匙作为指示的方向,是房间号码形成了一个环。而针对每种情况,形成的环数就是所要破坏的门的数量。所以要找寻k以内的环数的情况,并且因为1号门不能破坏,所以要减去,以1号门为单独的一个环且符合情况的数量。 1 #include 2 #include 3 typedef long long i64; 4 int main() 5 { 6 i64 s[25][25],f[25]; 7 int T,n,k,i,j; 8 memset(s,0,sizeof(s)); 9 s... 阅读全文
posted @ 2013-07-19 17:32 Ac_国士无双 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 最长公共子序列 1 #include 2 #include 3 #include 4 using namespace std; 5 int main() 6 { 7 int n,m,a1[105],a2[105],a[105][105],count=0; 8 while(scanf("%d%d",&n,&m)!=EOF) 9 {10 count++;11 if(n==0&&m==0)12 break;13 for(int i=0;i<n;i++)14 scanf("%d",&a1[i]);1... 阅读全文
posted @ 2013-07-19 14:24 Ac_国士无双 阅读(178) 评论(0) 推荐(0) 编辑