A: 信号与系统

Time Limit: 1000 MS Memory Limit: 65536 KB
Total Submit: 238 Accepted: 44 Page View: 69

Description

上决╇ф正在学习万恶的信号与系统(SAS),各种卷积、傅里叶等恶心的变化。现在,上决╇ф碰到了一个很简单但是很烦人的问题,又一个离散信号,要求出这个信号最大值和最小值出现的次数。上决╇ф现在很忙,这个问题就交给你了。

Input

  1. 第一排一个数T 0 < T <= 100 ),表示测试组数。
  2. 每组测试的第一排一个数n0 < n <= 100),表示这个信号有n个离散点。
  3. 接下一排有n个数,对于每一个数Ai,表示该点的信号值的大小,(-100 <= Ai <= 100)。

Output

  1. 对于每一组测试输出一排,格式为:"Case #X: A B"(不包括引号),A表示这个信号最大值出现的次数,B表示最小值出现的次数。X代测试表数据编号。
    Sample Input
  1. 2
  2. 6
  3. 1 1 2 2 3 3
  4. 5
  5. 79 79 79 79 79
    Sample Output
  1. Case #1: 2 2
  2. Case #2: 5 5
Status Clarify
膜拜巨巨都学这些了,各种卷积、傅里叶等,Orz
签到题、排序即可
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int n,T,i,iCase=;
  10. int a[];
  11. scanf("%d",&T);
  12. while(T--)
  13. {
  14. scanf("%d",&n);
  15. for(i=;i<=n;i++) scanf("%d",&a[i]);
  16. sort(a+,a+n+);
  17. int cnt1=,cnt2=;
  18. for(i=;i<=n;i++)
  19. {
  20. if(a[i]==a[i+]) cnt1++;
  21. else break;
  22. }
  23. for(i=n;i>=;i--)
  24. {
  25. if(a[i]==a[i-]) cnt2++;
  26. else break;
  27. }
  28. printf("Case #%d: %d %d\n",iCase++,cnt2,cnt1);
  29. }
  30. return ;
  31. }

 B: 小红开班会

Time Limit: 2000 MS Memory Limit: 65536 KB
Total Submit: 196 Accepted: 24 Page View: 44

Description

小红当了超级一班的辅导员,他召开了一次班会。超级一班共有n个人,但是开完会以后他看了下签到表,上面只有n-1个人的学号。小红想知道哪个人没来,他知道n个人的学号,但是由于人太多,小红找不出来,所以请你帮他找出没来的那个人的学号。

Input

  1. 第一行输入一个数字T。表示有T组数据。
  2. 每组输入共3行。
  3. 第一行1个数n,表示超级一班的人数(2<=n<=100000
  4. 第二行n个数,分别表示n个人的学号(每个数小于2^31,且n个数一定互不相同,两个数字之间以空格隔开)
  5. 第三行n-1个数,为签到表上的学号(输入保证每个数都为上一行的n个数之一,且n-1个数一定互不相同)

Output

  1. 每组数据输出一行,输出格式为:"Case #x: y"x表示这是第几组数据。y表示没来参加班会的人的学号。
    Sample Input
  1. 2
  2. 3
  3. 1 2 3
  4. 2 3
  5. 4
  6. 20121010 20131320 20121111 20111234
  7. 20131320 20111234 20121111
    Sample Output
  1. Case #1: 1
  2. Case #2: 20121010
Status Clarify
签到题、
方法1:排序
方法2:异或即可
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int n,T,i,iCase=;
  10. int a[],b[];
  11. scanf("%d",&T);
  12. while(T--)
  13. {
  14. scanf("%d",&n);
  15. for(i=;i<=n;i++) scanf("%d",&a[i]);
  16. for(i=;i<n;i++) scanf("%d",&b[i]);
  17. sort(a+,a+n+);
  18. sort(b+,b+n);
  19. int ans;
  20. for(i=;i<=n;i++)
  21. {
  22. if(a[i]!=b[i])
  23. {
  24. ans=a[i];
  25. break;
  26. }
  27. }
  28. printf("Case #%d: %d\n",iCase++,ans);
  29. }
  30. return ;
  31. }

 C: 小红去看花卉展

Time Limit: 2000 MS Memory Limit: 65536 KB
Total Submit: 23 Accepted: 0 Page View: 109

Description

春天来了,小红跑去看花卉展。花卉展摆了n排花,每排有m盘花卉,从左到右编号为1到m。每盘花卉都有一个标签,上面标明了这盘花卉的价格。

看到这一排一排的数字小红脑海里突然浮现出一个问题:是否存在一个区间[l,r],使得每排花卉区间[l,r]的花卉的价格和相等?如果存在,那么这样的区间最长为多少?

Input

  1. 第一行输入一个数字T,表示输入数据组数。
  2. 对于每组数据输入:
  3. 第一行两个数:nm1<=n<=30,1<=m<=10000
  4. 接下来输入n行,每行m个数字。第i行的第j个数,表示第i排的第j盘花卉的价格(输入保证每个数大于等于0且小于2^31)。

Output

  1. 对于每组数据,输出一行"Case #x: y"x表示这是输入的第几组数据,y表示满足条件的最长的区间。如果不存在,y为-1
    Sample Input
  1. 2
  2. 1 3
  3. 1 2 3
  4. 2 3
  5. 1 2 3
  6. 4 3 1
    Sample Output
  1. Case #1: 3
  2. Case #2: -1
Status Clarify
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <map>
  5. #include <string>
  6. #include <algorithm>
  7. using namespace std;
  8. #define INF 0x3f3f3f3f
  9. #define ll long long
  10. #define N 33
  11. #define M 10010
  12.  
  13. struct Node{
  14. int size;
  15. int a[N];
  16. Node(){}
  17. bool operator <(const Node &p)const{
  18. for(int i=;i<size;i++){
  19. if(a[i]!=p.a[i]) return a[i]<p.a[i];
  20. }
  21. return ;
  22. }
  23. };
  24. int n,m;
  25. int a[N][M];
  26. ll sum[N][M];
  27. ll con[N][M];
  28. map<Node,int> mp;
  29.  
  30. int main()
  31. {
  32. int T,i,j,iCase=;
  33. scanf("%d",&T);
  34. while(T--){
  35. mp.clear();
  36. scanf("%d%d",&n,&m);
  37. for(i=;i<=n;i++){
  38. sum[i][]=;
  39. for(j=;j<=m;j++){
  40. scanf("%d",&a[i][j]);
  41. sum[i][j]=sum[i][j-]+a[i][j];
  42. }
  43. }
  44. for(i=;i<=n;i++){
  45. con[i][]=;
  46. for(j=;j<=m;j++){
  47. con[i][j]=sum[i][j]-sum[][j];
  48. }
  49. }
  50.  
  51. int ans=-;
  52. for(j=;j<=m;j++){
  53. Node t;
  54. t.size=n-;
  55. for(i=;i<=n;i++){
  56. t.a[i-]=con[i][j];
  57. }
  58. if(!mp[t]) mp[t]=j+;
  59. else ans=max(ans,j-mp[t]+);
  60. }
  61. printf("Case #%d: %d\n",iCase++,ans);
  62. }
  63. return ;
  64. }
 

 D: islands打炉石传说

Time Limit: 1000 MS Memory Limit: 65536 KB
Total Submit: 64 Accepted: 10 Page View: 82

Description

islands最近在完一款游戏“炉石传说”,又名“魔兽英雄传”。炉石传说是一款卡牌类对战的游戏。游戏是2人对战,总的来说,里面的卡牌分成2类,一类是法术牌,另一类是随从牌(所谓随从就是怪物)。

为了简化问题,现在假设随从牌的作用是召唤一个具有一定攻击力的怪物,法术牌的作用是给某个随从增加一定攻击力。随从牌和法术牌的使用都需要消耗一定的法力值。现在islands有10点法力值,手上有n张牌(islands最多有10张牌,否者他将会被爆牌T_T),有些是法术牌,有些是随从牌。islands现在是大劣势,他想要是利用这10点法力值使得召唤出来的所有随从的攻击力总和最高(法力值可以不用完)。注意,任何法术牌都必须使用在某个召唤出来的随从上,也就是如果islands没有召唤过随从,他将不能使用任何法术牌。告诉islands他能召唤的随从的总攻击力最大是多少。

Input

  1. 首先输入测试数据组数TT<=10
  2. 每组数据首先输入一个n0<=n<=10),表示islandsn张牌接下来n行每行输入3个整数 cost0<=cost<=10),d(0或者1),w(|w|<=1000)。cost表示该牌的法力值消耗,如果d=0,表示该牌是攻击力为w的随从牌,如果d=1,表示是能给一个随从增加w攻击的法术牌。

Output

  1. 对于每组数据输出按照格式“Case #x: a”(不包括冒号)输出一行。其中x表示第x组测试数据,a表示对应的答案。
    Sample Input
  1. 2
  2. 1
  3. 1 0 100
  4. 1
  5. 1 1 100
    Sample Output
  1. Case #1: 100
  2. Case #2: 0
Status Clarify
水题、
方法1:暴力
方法2:01背包
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. using namespace std;
  6. #define ll long long
  7. #define N 10000
  8.  
  9. int n,s;
  10. int w1[],v1[],n1;
  11. int w0[],v0[],n0;
  12. int dp[];
  13.  
  14. int main()
  15. {
  16. int T,i,j,k,iCase=;
  17. scanf("%d",&T);
  18. while(T--)
  19. {
  20. n0=n1=;
  21. scanf("%d",&n);
  22. for(i=;i<=n;i++)
  23. {
  24. int a,b,c;
  25. scanf("%d%d%d",&a,&b,&c);
  26. if(b==)
  27. w0[++n0]=a,v0[n0]=c;
  28. else
  29. w1[++n1]=a,v1[n1]=c;
  30. }
  31. int ans=;
  32. int ww,vv;
  33. for(k=;k<=n0;k++)
  34. {
  35. memset(dp,,sizeof(dp));
  36. dp[]=v0[k];
  37. s=-w0[k];
  38. for(i=;i<=n0+n1;i++)
  39. {
  40. if(i==k) continue;
  41. if(i<=n0) ww=w0[i],vv=v0[i];
  42. else ww=w1[i-n0],vv=v1[i-n0];
  43. for(j=s;j>=ww;j--)
  44. {
  45. dp[j]=max(dp[j],dp[j-ww]+vv);
  46. }
  47. }
  48. int tmp=;
  49. for(j=;j<=;j++) tmp=max(tmp,dp[j]);
  50. ans=max(ans,tmp);
  51. }
  52. printf("Case #%d: %d\n",iCase++,ans);
  53. }
  54. return ;
  55. }

 E: 小红学数学

Time Limit: 1000 MS Memory Limit: 65536 KB
Total Submit: 184 Accepted: 43 Page View: 59

Description

众所周知,小红是一个不折不扣月收入好几E的大土豪,最近小红来swust学习数学,我上决╇ф这个小diaosi岂能错过抱大腿的机会?为什么小红要来swust学数学呢?毕竟钱多人傻,23333333。小红碰到的问题就是这么简单他都不会,求一个数的质因子个数。想抱大腿么?请继续……

Input

  1. 第一排一个数T,为测试组数。
  2. 每组一排只有一个数字n,(0< n<=10000),测试组数不超过20组。

Output

  1. 每组输出一排,"Case #X: "n的质因子的个数。X代表测试编号。
    Sample Input
  1. 2
  2. 10
  3. 5
    Sample Output
  1. Case #1: 2
  2. Case #2: 1

Hint

  1. 此题1不属于质数。
  2. 质因子:假设A是质数,且B%A==0,那么A就是B的质因子。
Status Clarify
签到题,暴力或者筛素数都行
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. using namespace std;
  6. #define ll long long
  7. #define N 10000
  8.  
  9. int tot;
  10. int prime[N+];
  11. bool isprime[N+];
  12. void init()
  13. {
  14. tot=;
  15. memset(isprime,,sizeof(isprime));
  16. isprime[]=isprime[]=;
  17. for(int i=;i<=N;i++)
  18. {
  19. if(isprime[i]) prime[tot++]=i;
  20. for(int j=;j<tot;j++)
  21. {
  22. if((ll)i*prime[j]>N) break;
  23. isprime[i*prime[j]]=;
  24. if(i%prime[j]==)
  25. break;
  26. }
  27. }
  28. }
  29. int main()
  30. {
  31. init();
  32. int n,T,i,iCase=;
  33. scanf("%d",&T);
  34. while(T--)
  35. {
  36. scanf("%d",&n);
  37. int ans=;
  38. for(int i=;i<tot;i++)
  39. {
  40. if(n%prime[i]==)
  41. ans++;
  42. }
  43. printf("Case #%d: %d\n",iCase++,ans);
  44. }
  45. return ;
  46. }

 F: 上决╇ф的IDE

Time Limit: 5000 MS Memory Limit: 65536 KB
Total Submit: 27 Accepted: 1 Page View: 25

Description

  1. 上决╇ф觉得Code::Blocks的编辑器太难用了,决定自己开发一个编辑器。现在,这个编辑器正处于开发的初期,只能进行剪切和粘贴成对的操作来处理特殊文本。该文本文件共有N行文本,每一行文本仅包含一个自然数,第一行为1、第二行为2,以此类推至N行为自然数N。假设对该文本文件执行一次“剪切和粘贴”操作含义如下:首先选定连续的若干行文本,“剪切”操作将选定的文本从文件中剪下(后面的内容将自动往前移动),而“粘贴”操作将剪切下来的文本插入到文件中的其他地方。上决╇ф想知道,在进行了连续若干次“剪切和粘贴”操作后,文本文件中前十行的内容,以验证这个编辑器的正确性。

Input

  1. 第一行一个整数T,表示测试组数。
  2. 每组的第一行包含两个用空格隔开的自然数NKN表示文件的总行数(10N100,000),K表示“剪切和粘贴”的总次数(1k100000)。
  3. 下面K行每一行包含一次“剪切和粘贴”操作的执行信息,每行包含三个用空格隔开自然数ABC,其中1ABN0CN-(B-A+1)。AB表示选定文本的第一行和最后一行,C表示被剪切下来的文本待插入处的前一行,如果C等于0则被剪切下来的的文本将被插入到文件的开头。

Output

  1. 对于每组测试,先输出一行"Case #X:"X表示测试编号。
  2. 接下来10行,为所有的操作都完成后的文本文件中前十行所包含的数字。
    Sample Input
  1. 2
  2. 13 3
  3. 6 12 1
  4. 2 9 0
  5. 10 13 8
  6. 10 1
  7. 2 4 2
    Sample Output
  1. Case #1:
  2. 6
  3. 7
  4. 8
  5. 9
  6. 10
  7. 11
  8. 12
  9. 2
  10. 3
  11. 4
  12. Case #2:
  13. 1
  14. 5
  15. 2
  16. 3
  17. 4
  18. 6
  19. 7
  20. 8
  21. 9
  22. 10
Status Clarify
方法1:暴力Splay
方法2:从后往前推
代码写得搓,将就一下
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<map>
  5. #include<string>
  6. #include<algorithm>
  7. using namespace std;
  8. #define INF 0x3f3f3f3f
  9. #define ll __int64
  10. #define N 100010
  11.  
  12. int n,m;
  13. int ansl;
  14. int ans[N];
  15. struct SplayTree
  16. {
  17. int ch[N][],pre[N],val[N],num[N],rev[N],sz[N];
  18. int top,root;
  19.  
  20. inline void Rotate(int x,int c){
  21. int y=pre[x];
  22. ch[y][!c]=ch[x][c];
  23. if(ch[x][c]) pre[ch[x][c]]=y;
  24. pre[x]=pre[y];
  25. if(pre[y]) ch[pre[y]][ch[pre[y]][]==y]=x;
  26. ch[x][c]=y;
  27. pre[y]=x;
  28. PushUp(y);
  29. if(y==root) root=x;
  30. }
  31. inline void Splay(int x,int f){
  32. while(pre[x]!=f)
  33. {
  34. if(pre[pre[x]]==f) Rotate(x,ch[pre[x]][]==x);
  35. else
  36. {
  37. int y=pre[x],z=pre[y];
  38. int c=(ch[z][]==y);
  39. if(ch[y][c]==x) Rotate(x,!c),Rotate(x,c);
  40. else Rotate(y,c),Rotate(x,c);
  41. }
  42. }
  43. PushUp(x);
  44. if(f==) root=x;
  45. }
  46. inline void SplayKth(int k,int f){
  47. int x=root;
  48. k+=;
  49. while()
  50. {
  51. if(k==sz[ch[x][]]+) break;
  52. else if(k<=sz[ch[x][]]) x=ch[x][];
  53. else k-=sz[ch[x][]]+,x=ch[x][];
  54. }
  55. Splay(x,f);
  56. }
  57. inline void PushUp(int x){
  58. sz[x]=sz[ch[x][]]+sz[ch[x][]]+;
  59. }
  60. inline void NewNode(int &x,int c,int f){
  61. x=++top;
  62. sz[x]=;
  63. ch[x][]=ch[x][]=rev[x]=;
  64. val[x]=c;
  65. pre[x]=f;
  66. }
  67. inline void Build(int &x,int l,int r,int f){
  68. if(l>r) return;
  69. int m=(l+r)>>;
  70. NewNode(x,num[m],f);
  71. Build(ch[x][],l,m-,x);
  72. Build(ch[x][],m+,r,x);
  73. PushUp(x);
  74. }
  75. inline void Init(int n){
  76. top=pre[]=ch[][]=ch[][]=sz[]=rev[]=;
  77. val[]=INF;
  78. for(int i=;i<=n;i++) num[i]=i;
  79. Build(root,,n+,);
  80. }
  81. void Res()
  82. {
  83. int l,r,tt;
  84. scanf("%d%d%d",&l,&r,&tt);
  85. int len=r-l+;
  86. l--;
  87. SplayKth(l,);
  88. SplayKth(r+,root);
  89. int x=ch[ch[root][]][];
  90. ch[ch[root][]][]=;
  91. PushUp(ch[root][]);
  92. PushUp(root);
  93. tt++;
  94. SplayKth(tt-,);
  95. SplayKth(tt,root);
  96. ch[ch[root][]][]=x;
  97. pre[ch[ch[root][]][]]=ch[root][];
  98. PushUp(ch[root][]);
  99. PushUp(root);
  100. }
  101. void Print(int x){
  102. if(ch[x][]) Print(ch[x][]);
  103. if(val[x]>= && val[x]<=n)
  104. ans[++ansl]=val[x];
  105. if(ch[x][]) Print(ch[x][]);
  106. }
  107. }t;
  108. int main()
  109. {
  110. int T,j,iCase=;
  111. scanf("%d",&T);
  112. while(T--)
  113. {
  114. scanf("%d%d",&n,&m);
  115. t.Init(n);
  116. printf("Case #%d:\n",iCase++);
  117. while(m--) t.Res();
  118. ansl=;
  119. t.SplayKth(t.root,);
  120. t.Print(t.root);
  121. for(int i=;i<=;i++) cout<<ans[i]<<endl;
  122. }
  123. return ;
  124. }

G: islands想吃糖果

Time Limit: 1000 MS Memory Limit: 65536 KB
Total Submit: 24 Accepted: 0 Page View: 80

Description

daidao买了很多糖果带到实验室,里面有n颗,islands看到了很高兴马上准备吃。daidao数了一下实验室的人有m个(包括daidao),问islands如果你能告诉我有多少种不同方案把这些糖果分给实验室的m个人,并且每人至少都要分一个,我就给你吃(对于2个方案,只要存在一个或一个以上的人分的数目不同就是2个不同的方案)。旁边的w703710691d说这可难不倒islands,再加上一个条件,要求每个人分的糖果的个数的最大公约数正好为k。(m个数的最大公约数是说有能整除这m个数中的最大的)。由于答案很大,daidao要求答案对1000000007取模。这下islands难住了,你能帮助islands吃到糖果吗。

Input

  1. 首先输入一个证书T表示测试数据组数(T<100
  2. 接下来T行每行输入3个正整数,n,m,k。( 0 < n,m,k < = 200

Output

  1. 对于每组数据输出按照格式“Case #x: a”(不包括冒号)输出一行。其中x表示第x组测试数据,a表示对应的答案。
    Sample Input
  1. 3
  2. 1 1 1
  3. 4 2 2
  4. 5 3 1
    Sample Output
  1. Case #1: 1
  2. Case #2: 1
  3. Case #3: 6
Status Clarify
后面再补,- -
 

H: islands学习几何

Time Limit: 1000 MS Memory Limit: 65536 KB
Total Submit: 4 Accepted: 0 Page View: 22

Description

由于实验室的几何大神都纷纷退役了,islands不得不担任起学习几何的重任。

有一天他遇到了这样一道题。如右图,有一个三角形ABC,圆F和线段AB相切,和CA,CB延长线相切。圆E和线段AC相切,和BA,BC延长线相切。圆D和线段BC相切,和AB,AC延长线相切。现在已知三角形ABC的三边长a,b,c。分别求三角形DEF的面积和图中阴影部分的总面积。

Input

  1. 首先输入测试组数T.(T<=10000
  2. 接下来每组数据输入2个正整数a,b,c ( 0 < a,b,c <= 1000),表示三角形ABC的三边长吗,输入保证a,b,c能组成三角形。

Output

  1. 对于每组测试数据输出一行“Case #x: f1 f2”(不包括冒号),x表示第x组数据,f1表示该组数据三角形DEF的面积,f2表示阴影部分的面积(所有答案四舍五入到小数点后面2位)。
    Sample Input
  1. 2
  2. 3 4 5
  3. 10 11 12
    Sample Output
  1. Case #1: 30.00 21.62
  2. Case #2: 211.37 144.73
Status Clarify
后面再补,- -
 

I: 小红灌溉

Time Limit: 1000 MS Memory Limit: 65536 KB
Total Submit: 17 Accepted: 0 Page View: 104

Description

小红家有n行田地,每行田地由m块大小为1*1的小田地组成。这些田地构成了一个n*m的矩形。小红在某些小田地里种植了蔬菜。现在小红要给蔬菜灌溉。小红每次可以选择给某一行或某一列的田地灌溉。但是一块种植了蔬菜的田地只能被灌溉一次。由于种种原因,灌溉某行或某列的耗电量不同。所以小红想知道,灌溉完所有蔬菜的耗电量最少为多少?

Input

  1. 第一行输入一个数字T,表示输入数据组数。
  2. 接下来每组数据:
  3. 第一行输入两个数nm1<=n<=100,1<=m<=100
  4. 接下来输入n行,每行m个数字。第i行的第j个数为0表示第i行的第j块田地为空地,如果为1,表示第i行的第j列种植有蔬菜。
  5. 接下来一行输入n个数字,第i个数字,表示灌溉第i行的耗电量。(每个数字大于0小于等于1000)
  6. 接下来一行输入m个数字,第i个数字,表示灌溉第i列的耗电量。(每个数字大于0小于等于1000

Output

  1. 输出T行,第i行输出"Case #i: y"y为第i组数据的答案。
    Sample Input
  1. 1
  2. 2 2
  3. 1 0
  4. 0 1
  5. 1 2
  6. 2 1
    Sample Output
  1. Case #1: 2
Status Clarify
行列建图,对每个连通块二染色取最小
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <cstring>
  6. using namespace std;
  7. #define INF 0x3f3f3f3f
  8. #define ll long long
  9. #define N 510
  10. #define M N*N/2
  11.  
  12. struct Edge
  13. {
  14. int to,next;
  15. }edge[M];
  16. int head[N],tot;
  17.  
  18. int n,m;
  19. int a[N][N];
  20. int cost[N];
  21. int color[N];
  22. int t[];
  23.  
  24. void init()
  25. {
  26. tot=;
  27. memset(head,-,sizeof(head));
  28. }
  29. void add(int u,int v)
  30. {
  31. edge[tot].to=v;
  32. edge[tot].next=head[u];
  33. head[u]=tot++;
  34. }
  35. void dfs(int u,int c)
  36. {
  37. color[u]=c;
  38. t[c]+=cost[u];
  39. for(int i=head[u];i!=-;i=edge[i].next){
  40. int v=edge[i].to;
  41. if(color[v]==-)
  42. dfs(v,!c);
  43. }
  44. }
  45. int main()
  46. {
  47. int T,iCase=;
  48. scanf("%d",&T);
  49. while(T--){
  50. init();
  51. scanf("%d%d",&n,&m);
  52. for(int i=;i<=n;i++){
  53. for(int j=;j<=m;j++){
  54. scanf("%d",&a[i][j]);
  55. }
  56. }
  57. for(int i=;i<=n+m;i++) scanf("%d",&cost[i]);
  58. for(int i=;i<=n;i++){
  59. for(int j=;j<=m;j++){
  60. if(a[i][j]){
  61. add(i,j+n);
  62. add(j+n,i);
  63. }
  64. }
  65. }
  66. int ans=;
  67. memset(color,-,sizeof(color));
  68. for(int i=;i<=n+m;i++){
  69. t[]=t[]=;
  70. if(color[i]==-) dfs(i,);
  71. ans+=min(t[],t[]);
  72. }
  73. printf("Case #%d: %d\n",iCase++,ans);
  74. }
  75. return ;
  76. }

 J: islands的难题

Time Limit: 1000 MS Memory Limit: 65536 KB
Total Submit: 94 Accepted: 7 Page View: 90

Description

最近islands遇到一个难题,他想请人帮他解决。给一个数列a1,a2……an。有m个操作,每个操作是下面2种之一。

第1种操作是询问区间[l,r]上的值。

第2种操作是使得第k个数加上v。

Input

  1. 首先输入T表示测试数据组数(T<=5)
  2. 每组数据第一行输入n,m(n,m<=100000)表示n个数和m个操作。
  3. 接下来1行输入n个数,表示ai。(0<=a[i]<=100000
  4. 接下来m行每行输入d(0或者1),l,r
  5. d=0表示第1操作 0 < l <= r <= n),表示询问[l,r]上的答案。
  6. d=1表示第2种操作( 0 < l <= n, 0 <= r <= 1000),表示a[l]加上r

Output

  1. 对于每组测试数据首先输出一行“Case #x:”(不包括冒号)x表示第x组数据
  2. 对于m个操作,如果是1操作输出一行表示对应答案。
    Sample Input
  1. 1
  2. 5 5
  3. 1 2 3 4 5
  4. 0 1 5
  5. 0 3 4
  6. 1 5 1
  7. 0 1 5
  8. 0 3 4
    Sample Output
  1. Case #1:
  2. 55
  3. 11
  4. 60
  5. 11
Status Clarify
简单线段树,维护区间和和区间权和(不知道咋说,见代码)
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. using namespace std;
  5. #define ll long long
  6. #define INF 0x3f3f3f3f
  7. #define N 100010
  8.  
  9. ll n,m;
  10. ll a[N];
  11. ll sum1[N<<];
  12. ll sum2[N<<];
  13.  
  14. void pushup(ll rt)
  15. {
  16. sum1[rt]=sum1[rt<<]+sum1[rt<<|];
  17. sum2[rt]=sum2[rt<<]+sum2[rt<<|];
  18. }
  19. void build(ll l,ll r,ll rt)
  20. {
  21. if(l==r)
  22. {
  23. sum2[rt]=a[l];
  24. sum1[rt]=l*a[l];
  25. return;
  26. }
  27. ll m=(l+r)>>;
  28. build(l,m,rt<<);
  29. build(m+,r,rt<<|);
  30. pushup(rt);
  31. }
  32. void update(ll l,ll r,ll rt,ll pos,ll c)
  33. {
  34. if(l==r)
  35. {
  36. sum1[rt]+=pos*c;
  37. sum2[rt]+=c;
  38. return;
  39. }
  40. ll m=(l+r)>>;
  41. if(pos<=m) update(l,m,rt<<,pos,c);
  42. else update(m+,r,rt<<|,pos,c);
  43. pushup(rt);
  44. }
  45. ll query(ll l,ll r,ll rt,ll L,ll R,ll op)
  46. {
  47. if(l==L && R==r)
  48. {
  49. if(op==) return sum1[rt];
  50. else return sum2[rt];
  51. }
  52. ll m=(l+r)>>;
  53. if(R<=m) return query(l,m,rt<<,L,R,op);
  54. else if(L>m) return query(m+,r,rt<<|,L,R,op);
  55. else return query(l,m,rt<<,L,m,op)+query(m+,r,rt<<|,m+,R,op);
  56. }
  57. int main()
  58. {
  59. ll T,i,j,iCase=;
  60. scanf("%lld",&T);
  61. while(T--)
  62. {
  63. scanf("%lld%lld",&n,&m);
  64. for(i=;i<=n;i++) scanf("%lld",&a[i]);
  65. build(,n,);
  66. printf("Case #%lld:\n",iCase++);
  67. while(m--)
  68. {
  69. ll op,a,b;
  70. scanf("%lld%lld%lld",&op,&a,&b);
  71. if(op==)
  72. printf("%lld\n",query(,n,,a,b,)-(a-)*query(,n,,a,b,));
  73. else
  74. update(,n,,a,b);
  75. }
  76. }
  77. return ;
  78. }

信息学院第九届ACM程序设计竞赛题解的更多相关文章

  1. 哈尔滨工业大学(威海)第九届ACM程序设计竞赛 Virtual Youtuber

    链接 [https://ac.nowcoder.com/acm/contest/624/G] 题意 其实题意说的辣鸡死了,没有说明确. y is the subsequences that its s ...

  2. 西南科技大学第十届ACM程序设计竞赛题解

    A.德州扑克 B. 我恨11(1089) 问题描述 11是一个孤独的数字,小明十分讨厌这个数字,因此如果哪个数字中出现了11或者该数字是11的倍数,他同样讨厌这个数字.现在问题来了,在闭区间[L,R] ...

  3. 《ACM国际大学生程序设计竞赛题解Ⅰ》——基础编程题

    这个专栏开始介绍一些<ACM国际大学生程序设计竞赛题解>上的竞赛题目,读者可以配合zju/poj/uva的在线测评系统提交代码(今天zoj貌似崩了). 其实看书名也能看出来这本书的思路,就 ...

  4. 华南师大 2017 年 ACM 程序设计竞赛新生初赛题解

    题解 被你们虐了千百遍的题目和 OJ 也很累的,也想要休息,所以你们别想了,行行好放过它们,我们来看题解吧... A. 诡异的计数法 Description cgy 太喜欢质数了以至于他计数也需要用质 ...

  5. 电信学院第一届新生程序设计竞赛题解及std

    首先非常感谢各位同学的参加,还有出题验题同学的辛勤付出 昨天想偷懒就是不想再把我C++11的style改没了,大家看不懂的可以百度一下哦,懒得再写gcc了,毕竟代码是通的 //代表的是行注释,所以那个 ...

  6. 第十四届中北大学ACM程序设计竞赛 J.ZBT的游戏

    问题描述 第14届中北大学程序设计竞赛来了,集训队新买了一大堆气球,气球一共有K种颜色(1<=K<=256),气球的颜色从1-K编号. ZBT童心未泯,他发明了一种摆放气球的游戏,规则如下 ...

  7. 《ACM国际大学生程序设计竞赛题解I》——6.10

    Pku 1143: Description Christine and Matt are playing an exciting game they just invented: the Number ...

  8. 《ACM国际大学生程序设计竞赛题解I》——6.11

    pku 1107: Description Weird Wally's Wireless Widgets, Inc. manufactures an eclectic assortment of sm ...

  9. 《ACM国际大学生程序设计竞赛题解I》——6.8

    Poj1068: Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in ...

随机推荐

  1. window2003安全设置

    1.    网上邻居->右键 属性->本地连接 右键属性->Microsoft网络的文件和打印机共享去掉选中   (影响端口: 139,445) 2.    禁止ADMIN$缺省共享 ...

  2. QT定制有标题的扁平化下拉框控件

    关键字:QT,QComboBox,QLineEdit,QListView,QPushButton,QMenu,QWidgetAction,setStyleSheet OS:Windows 7 方法一: ...

  3. 在Qt Creator中添加OpenCV库

    在项目的pro文件中添加如下代码:INCLUDEPATH += D:/opencv/build/include win32:CONFIG(debug, debug|release): {LIBS += ...

  4. 【socket】TCP 和 UDP 在socket编程中的区别

    一.TCP与UDP的区别 基于连接与无连接  对系统资源的要求(TCP较多,UDP少)  UDP程序结构较简单  流模式与数据报模式  TCP保证数据正确性,UDP可能丢包  TCP保证数据顺序,UD ...

  5. 统一iOS客户端和服务器端认证

    最近公司的同事业余时间搞了一个内部的类about.me(https://about.me/)的网站Ocelots,想来是一个很洋气的注意,以后跟客户介绍公司的时候,直接登录该网站,谈到谁的时候,就打开 ...

  6. tableView的基本使用(改良版)

    @interface ViewController ()<UITableViewDataSource, UITableViewDelegate> { int i;//用来计算接受通知的次数 ...

  7. c#类库中使用Session

    网站开发中,为了保存用户的信息,有时候需要使用session.如果我们在aspx页面中使用Session,只需要Session["key"]=value就可以,获取时使用int u ...

  8. poj 3522 Slim Span (最小生成树kruskal)

    http://poj.org/problem?id=3522 Slim Span Time Limit: 5000MS   Memory Limit: 65536K Total Submissions ...

  9. bzoj 2744: [HEOI2012]朋友圈 二分图匹配

    2744: [HEOI2012]朋友圈 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 612  Solved: 174[Submit][Status] ...

  10. Ubuntu环境下手动配置zookeeper

    配置zookeeper 注意:因为是单机伪分布式配置,故同一机器上有3个server zookeeper文件格式如下 home---zookeeper---server0---zookeeper | ...