L2-001. 紧急救援

作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图。在地图上显示有多个分散的城市和一些连接城市的快速道路。每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上。当其他城市有紧急求助电话给你的时候,你的任务是带领你的救援队尽快赶往事发地,同时,一路上召集尽可能多的救援队。

输入格式:

输入第一行给出4个正整数N、M、S、D,其中N(2<=N<=500)是城市的个数,顺便假设城市的编号为0~(N-1);M是快速道路的条数;S是出发地的城市编号;D是目的地的城市编号。第二行给出N个正整数,其中第i个数是第i个城市的救援队的数目,数字间以空格分隔。随后的M行中,每行给出一条快速道路的信息,分别是:城市1、城市2、快速道路的长度,中间用空格分开,数字均为整数且不超过500。输入保证救援可行且最优解唯一。

输出格式:

第一行输出不同的最短路径的条数和能够召集的最多的救援队数量。第二行输出从S到D的路径中经过的城市编号。数字间以空格分隔,输出首尾不能有多余空格。

输入样例:

  1. 4 5 0 3
  2. 20 30 40 10
  3. 0 1 1
  4. 1 3 2
  5. 0 3 3
  6. 0 2 2
  7. 2 3 2

输出样例:

  1. 2 60
  2. 0 1 3
  1. //2017-03-17
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <queue>
  6. #include <stack>
  7.  
  8. using namespace std;
  9.  
  10. const int N = ;
  11. const int inf = 0x3f3f3f3f;
  12. int n, m, G[N][N], dis[N], vis[N], pre[N], way[N], maxpeo[N];
  13.  
  14. int dijkstra(int s, int d)
  15. {
  16. for(int i = ; i < n; i++)
  17. {
  18. dis[i] = G[s][i];
  19. if(G[s][i] != inf){
  20. pre[i] = s;
  21. way[i]++;
  22. }
  23. }
  24. pre[s] = -;
  25. dis[s] = ;
  26. vis[s] = ;
  27. way[s] = ;
  28. int mindis, u;
  29. maxpeo[s] = G[s][s];
  30. for(int i = ; i < n; i++)
  31. {
  32. mindis = inf;
  33. for(int j = ; j < n; j++)
  34. if(!vis[j] && dis[j] < mindis)
  35. {
  36. mindis = dis[j];
  37. u = j;
  38. }
  39. vis[u] = ;
  40. for(int v = ; v < n; v++)
  41. {
  42. if(vis[v] || G[u][v]==inf)continue;
  43. if(dis[v] > dis[u]+G[u][v]){
  44. dis[v] = dis[u]+G[u][v];
  45. pre[v] = u;
  46. maxpeo[v] = maxpeo[u] + G[v][v];
  47. way[v] = way[u];
  48. }else if(dis[v] == dis[u]+G[u][v]){
  49. way[v] += way[u];
  50. if(maxpeo[v] < maxpeo[u]+G[v][v]){
  51. maxpeo[v] = maxpeo[u] + G[v][v];
  52. pre[v] = u;
  53. }
  54. }
  55. }
  56. }
  57. return maxpeo[d]+maxpeo[s];
  58. }
  59.  
  60. int main()
  61. {
  62. int s, d, u, v, w;
  63. while(cin>>n>>m>>s>>d)
  64. {
  65. for(int i = ; i < n; i++)
  66. {
  67. for(int j = ; j < n; j++)
  68. G[i][j] = inf;
  69. vis[i] = ;
  70. dis[i] = inf;
  71. pre[i] = -;
  72. way[i] = ;
  73. maxpeo[i] = ;
  74. cin>>G[i][i];
  75. maxpeo[i] = G[i][i];
  76. }
  77. for(int i = ; i < m; i++)
  78. {
  79. cin>>u>>v>>w;
  80. G[u][v] = G[v][u] = w;
  81. }
  82. int peo = dijkstra(s, d);
  83. int pr = d;
  84. stack<int> sk;
  85. while(pr != s)
  86. {
  87. sk.push(pr);
  88. pr = pre[pr];
  89. }
  90. cout<<way[d]<<" "<<peo<<endl;
  91. cout<<s;
  92. int o;
  93. while(!sk.empty())
  94. {
  95. o = sk.top();
  96. cout<<" "<<o;
  97. sk.pop();
  98. }
  99. cout<<endl;
  100. }
  101.  
  102. return ;
  103. }

L2-002. 链表去重

给定一个带整数键值的单链表L,本题要求你编写程序,删除那些键值的绝对值有重复的结点。即对任意键值K,只有键值或其绝对值等于K的第一个结点可以被保留。同时,所有被删除的结点必须被保存在另外一个链表中。例如:另L为21→-15→-15→-7→15,则你必须输出去重后的链表21→-15→-7、以及被删除的链表-15→15。

输入格式:

输入第一行包含链表第一个结点的地址、以及结点个数N(<= 105 的正整数)。结点地址是一个非负的5位整数,NULL指针用-1表示。

随后N行,每行按下列格式给出一个结点的信息:

Address Key Next

其中Address是结点的地址,Key是绝对值不超过104的整数,Next是下一个结点的地址。

输出格式:

首先输出去重后的链表,然后输出被删除结点组成的链表。每个结点占一行,按输入的格式输出。

输入样例:

  1. 00100 5
  2. 99999 -7 87654
  3. 23854 -15 00000
  4. 87654 15 -1
  5. 00000 -15 99999
  6. 00100 21 23854

输出样例:

  1. 00100 21 23854
  2. 23854 -15 99999
  3. 99999 -7 -1
  4. 00000 -15 87654
  5. 87654 15 -1
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <list>
  6.  
  7. using namespace std;
  8.  
  9. const int N = 1e6+;
  10. int ne[N], ke[N], book[];
  11. struct node
  12. {
  13. int add, key, next;
  14. void setNode(int a, int k, int n){
  15. this->add = a;
  16. this->key = k;
  17. this->next = n;
  18. }
  19. };
  20.  
  21. int main()
  22. {
  23. int s, n, pos;
  24. while(cin>>s>>n)
  25. {
  26. int ad;
  27. for(int i = ; i < n; i++)
  28. {
  29. cin>>ad;
  30. cin>>ke[ad]>>ne[ad];
  31. }
  32. list<node> l1, l2;
  33. list<node>::iterator it;
  34. node tmp;
  35. memset(book, , sizeof(book));
  36. pos = s;
  37. book[abs(s)] = ;
  38. tmp.setNode(pos, ke[pos], ne[pos]);
  39. l1.push_back(tmp);
  40. pos = ne[pos];
  41. while(pos != -)
  42. {
  43. if(book[abs(ke[pos])]){
  44. if(!l2.empty()){
  45. tmp = l2.back();
  46. tmp.next = pos;
  47. l2.pop_back();
  48. l2.push_back(tmp);
  49. }
  50. tmp.setNode(pos, ke[pos], ne[pos]);
  51. l2.push_back(tmp);
  52. }else{
  53. book[abs(ke[pos])] = ;
  54. if(!l1.empty()){
  55. tmp = l1.back();
  56. tmp.next = pos;
  57. l1.pop_back();
  58. l1.push_back(tmp);
  59. }
  60. tmp.setNode(pos, ke[pos], ne[pos]);
  61. l1.push_back(tmp);
  62. }
  63. pos = ne[pos];
  64. }
  65. tmp = l1.back(); tmp.next = -;
  66. l1.pop_back();l1.push_back(tmp);
  67. for(it = l1.begin(); it != l1.end(); it++){
  68. if(it->next == -)printf("%05d %d %d\n", it->add, it->key, it->next);
  69. else printf("%05d %d %05d\n", it->add, it->key, it->next);
  70. }
  71. if(!l2.empty()){
  72. tmp = l2.back(); tmp.next = -;
  73. l2.pop_back();l2.push_back(tmp);
  74. }
  75. for(it = l2.begin(); it != l2.end(); it++){
  76. if(it->next == -)printf("%05d %d %d\n", it->add, it->key, it->next);
  77. else printf("%05d %d %05d\n", it->add, it->key, it->next);
  78. }
  79. }
  80.  
  81. return ;
  82. }

L2-003. 月饼

 

月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有种类月饼的库存量、总售价、以及市场的最大需求量,请你计算可以获得的最大收益是多少。

注意:销售时允许取出一部分库存。样例给出的情形是这样的:假如我们有3种月饼,其库存量分别为18、15、10万吨,总售价分别为75、72、45亿元。如果市场的最大需求量只有20万吨,那么我们最大收益策略应该是卖出全部15万吨第2种月饼、以及5万吨第3种月饼,获得 72 + 45/2 = 94.5(亿元)。

输入格式:

每个输入包含1个测试用例。每个测试用例先给出一个不超过1000的正整数N表示月饼的种类数、以及不超过500(以万吨为单位)的正整数D表示市场最大需求量。随后一行给出N个正数表示每种月饼的库存量(以万吨为单位);最后一行给出N个正数表示每种月饼的总售价(以亿元为单位)。数字间以空格分隔。

输出格式:

对每组测试用例,在一行中输出最大收益,以亿元为单位并精确到小数点后2位。

输入样例:

  1. 3 20
  2. 18 15 10
  3. 75 72 45

输出样例:

  1. 94.50
  1. //2017-03-18
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. const int N = ;
  10. struct node{
  11. double a, b;
  12. double c;
  13. bool operator < (const node& x){
  14. return c > x.c;
  15. }
  16. }moom[N];
  17.  
  18. int main()
  19. {
  20. int n, need;
  21. while(cin>>n>>need)
  22. {
  23. for(int i = ; i < n; i++)
  24. cin>>moom[i].a;
  25. for(int i = ; i < n; i++)
  26. cin>>moom[i].b;
  27. for(int i = ; i < n; i++)
  28. moom[i].c = moom[i].b*1.0/moom[i].a;
  29. sort(moom, moom+n);
  30. double ans = ;
  31. for(int i = ; i < n; i++)
  32. {
  33. if(need < moom[i].a){
  34. ans += moom[i].c*need;
  35. break;
  36. }else{
  37. ans += moom[i].b;
  38. need -= moom[i].a;
  39. }
  40. }
  41. printf("%.2lf\n", ans);
  42. }
  43.  
  44. return ;
  45. }

L2-004. 这是二叉搜索树吗?

一棵二叉搜索树可被递归地定义为具有下列性质的二叉树:对于任一结点,

  • 其左子树中所有结点的键值小于该结点的键值;
  • 其右子树中所有结点的键值大于等于该结点的键值;
  • 其左右子树都是二叉搜索树。

所谓二叉搜索树的“镜像”,即将所有结点的左右子树对换位置后所得到的树。

给定一个整数键值序列,现请你编写程序,判断这是否是对一棵二叉搜索树或其镜像进行前序遍历的结果。

输入格式:

输入的第一行给出正整数N(<=1000)。随后一行给出N个整数键值,其间以空格分隔。

输出格式:

如果输入序列是对一棵二叉搜索树或其镜像进行前序遍历的结果,则首先在一行中输出“YES”,然后在下一行输出该树后序遍历的结果。数字间有1个空格,一行的首尾不得有多余空格。若答案是否,则输出“NO”。

输入样例1:

  1. 7
  2. 8 6 5 7 10 8 11

输出样例1:

  1. YES
  2. 5 7 6 8 11 10 8

输入样例2:

  1. 7
  2. 8 10 11 8 6 7 5

输出样例2:

  1. YES
  2. 11 8 10 7 5 6 8

输入样例3:

  1. 7
  2. 8 6 8 5 10 9 11

输出样例3:

  1. NO
  1. //2017-03-19
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. const int N = ;
  9. int bt[N], bst1[N], bst2[N], ANS[N], n, cnt;
  10. struct node{
  11. int data;
  12. node *lson, *rson;
  13. node(int d):data(d), lson(NULL), rson(NULL){}
  14. };
  15.  
  16. class BST
  17. {
  18. public:
  19. node *rt;
  20. BST():rt(NULL){}
  21. void insert(int a)
  22. {
  23. node* nd = new node(a);
  24. if(rt == NULL){
  25. rt = nd;
  26. }else{
  27. node *p = rt, *q = NULL;
  28. while(p != NULL){
  29. q = p;
  30. if(a < p->data){
  31. p = p->lson;
  32. }else{
  33. p = p->rson;
  34. }
  35. }
  36. if(a < q->data)q->lson = nd;
  37. else q->rson = nd;
  38. }
  39. }
  40. };
  41.  
  42. void preOrder1(node* id)
  43. {
  44. if(id != NULL)
  45. {
  46. bst1[cnt] = id->data;
  47. cnt++;
  48. preOrder1(id->lson);
  49. preOrder1(id->rson);
  50. }
  51. }
  52.  
  53. void preOrder2(node* id)
  54. {
  55. if(id != NULL)
  56. {
  57. bst2[cnt] = id->data;
  58. cnt++;
  59. preOrder2(id->rson);
  60. preOrder2(id->lson);
  61. }
  62. }
  63.  
  64. void postOrder1(node* id)
  65. {
  66. if(id != NULL){
  67. postOrder1(id->lson);
  68. postOrder1(id->rson);
  69. ANS[cnt] = id->data;
  70. cnt++;
  71. }
  72. }
  73.  
  74. void postOrder2(node* id)
  75. {
  76. if(id != NULL){
  77. postOrder2(id->rson);
  78. postOrder2(id->lson);
  79. ANS[cnt] = id->data;
  80. cnt++;
  81. }
  82. }
  83.  
  84. int main()
  85. {
  86. while(cin>>n)
  87. {
  88. BST bst;
  89. for(int i = ; i < n; i++)
  90. {
  91. cin>>bt[i];
  92. bst.insert(bt[i]);
  93. }
  94. cnt = ;
  95. preOrder1(bst.rt);
  96. cnt = ;
  97. preOrder2(bst.rt);
  98. bool fg1 = true, fg2 = true;
  99. for(int i = ; i < n; i++){
  100. if(bt[i] != bst1[i])fg1 = false;
  101. if(bt[i] != bst2[i])fg2 = false;
  102. }
  103. if(fg1){
  104. cout<<"YES"<<endl;
  105. cnt = ;
  106. postOrder1(bst.rt);
  107. for(int i = ; i < n; i++)
  108. if(i == n-)cout<<ANS[i]<<endl;
  109. else cout<<ANS[i]<<" ";
  110. }else if(fg2){
  111. cout<<"YES"<<endl;
  112. cnt = ;
  113. postOrder2(bst.rt);
  114. for(int i = ; i < n; i++)
  115. if(i == n-)cout<<ANS[i]<<endl;
  116. else cout<<ANS[i]<<" ";
  117. }else cout<<"NO"<<endl;
  118. }
  119.  
  120. return ;
  121. }

L2-005. 集合相似度

给定两个整数集合,它们的相似度定义为:Nc/Nt*100%。其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数。你的任务就是计算任意一对给定集合的相似度。

输入格式:

输入第一行给出一个正整数N(<=50),是集合的个数。随后N行,每行对应一个集合。每个集合首先给出一个正整数M(<=104),是集合中元素的个数;然后跟M个[0, 109]区间内的整数。

之后一行给出一个正整数K(<=2000),随后K行,每行对应一对需要计算相似度的集合的编号(集合从1到N编号)。数字间以空格分隔。

输出格式:

对每一对需要计算的集合,在一行中输出它们的相似度,为保留小数点后2位的百分比数字。

输入样例:

  1. 3
  2. 3 99 87 101
  3. 4 87 101 5 87
  4. 7 99 101 18 5 135 18 99
  5. 2
  6. 1 2
  7. 1 3

输出样例:

  1. 50.00%
  2. 33.33%
  1. //2017-03-19
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <set>
  7.  
  8. using namespace std;
  9.  
  10. int se[][], cnt[];
  11.  
  12. double merge(int a, int b)
  13. {
  14. int nt = , nc = ;
  15. int cnt1 = , cnt2 = ;
  16. while(cnt1 < cnt[a] && cnt2 < cnt[b])
  17. {
  18. if(se[a][cnt1] < se[b][cnt2]){
  19. nt++;
  20. cnt1++;
  21. }else if(se[a][cnt1] > se[b][cnt2]){
  22. nt++;
  23. cnt2++;
  24. }else{
  25. nt++;
  26. nc++;
  27. cnt1++;
  28. cnt2++;
  29. }
  30. }
  31. if(cnt1<cnt[a])nt += cnt[a]-cnt1;
  32. if(cnt2<cnt[b])nt += cnt[b]-cnt2;
  33. return nc*1.0/nt;
  34. }
  35.  
  36. int main()
  37. {
  38. int n, m, a;
  39. while(cin>>n)
  40. {
  41. memset(cnt, , sizeof(cnt));
  42. for(int i = ; i <= n; i++)
  43. {
  44. cin>>m;
  45. set<int> S;
  46. set<int>::iterator it;
  47. for(int j = ; j < m; j++)
  48. {
  49. cin>>a;
  50. it = S.find(a);
  51. if(it == S.end()){
  52. S.insert(a);
  53. se[i][cnt[i]] = a;
  54. cnt[i]++;
  55. }
  56. }
  57. sort(se[i], se[i]+cnt[i]);
  58. }
  59. cin>>m;
  60. int s1, s2;
  61. while(m--)
  62. {
  63. cin>>s1>>s2;
  64. double ans = merge(s1, s2)*;
  65. printf("%.2lf%\n", ans);
  66. }
  67. }
  68.  
  69. return ;
  70. }

L2-006. 树的遍历

给定一棵二叉树的后序遍历和中序遍历,请你输出其层序遍历的序列。这里假设键值都是互不相等的正整数。

输入格式:

输入第一行给出一个正整数N(<=30),是二叉树中结点的个数。第二行给出其后序遍历序列。第三行给出其中序遍历序列。数字间以空格分隔。

输出格式:

在一行中输出该树的层序遍历的序列。数字间以1个空格分隔,行首尾不得有多余空格。

输入样例:

  1. 7
  2. 2 3 1 5 7 6 4
  3. 1 2 3 4 5 6 7

输出样例:

  1. 4 1 6 3 5 7 2
  1. //2017-03-20
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <queue>
  6.  
  7. using namespace std;
  8.  
  9. int post[], in[], ANS[];
  10. struct node{
  11. int data;
  12. node *lson, *rson;
  13. node(int d):data(d), lson(NULL), rson(NULL){}
  14. };
  15.  
  16. struct BT{
  17. node *root;
  18. void rebuild(int n)
  19. {
  20. root = buildTree(post, in, n);
  21. }
  22. node* buildTree(int *post, int *in, int n)
  23. {
  24. if(n < )return NULL;
  25. node *rt = new node(post[n-]);
  26. if(n == )return rt;
  27. int R;
  28. for(int i = ; i < n; i++)
  29. {
  30. if(in[i] == post[n-]){
  31. R = i;
  32. break;
  33. }
  34. }
  35. rt->lson = buildTree(post, in, R);
  36. rt->rson = buildTree(post+R, in+R+, n-R-);
  37. return rt;
  38. }
  39. void levelOrder()
  40. {
  41. queue<node*> q;
  42. q.push(root);
  43. node *h;
  44. int cnt = ;
  45. while(!q.empty()){
  46. h = q.front();
  47. q.pop();
  48. ANS[cnt++] = h->data;
  49. if(h->lson)q.push(h->lson);
  50. if(h->rson)q.push(h->rson);
  51. }
  52. for(int i = ; i < cnt; i++)
  53. if(i == cnt-)cout<<ANS[i]<<endl;
  54. else cout<<ANS[i]<<" ";
  55. }
  56. };
  57.  
  58. int main()
  59. {
  60. int n;
  61. while(cin>>n)
  62. {
  63. for(int i = ; i < n; i++)
  64. cin>>post[i];
  65. for(int i = ; i < n; i++)
  66. cin>>in[i];
  67. BT bt;
  68. bt.rebuild(n);
  69. bt.levelOrder();
  70. }
  71.  
  72. return ;
  73. }

L2-008. 最长对称子串

对给定的字符串,本题要求你输出最长对称子串的长度。例如,给定"Is PAT&TAP symmetric?",最长对称子串为"s PAT&TAP s",于是你应该输出11。

输入格式:

输入在一行中给出长度不超过1000的非空字符串。

输出格式:

在一行中输出最长对称子串的长度。

输入样例:

  1. Is PAT&TAP symmetric?

输出样例:

  1. 11
  1. //2017-03-19
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. string str;
  9. int len;
  10.  
  11. int search(int pos)
  12. {
  13. int l, r, ans = ;
  14. l = pos-;
  15. r = pos+;
  16. while(l >= && r < len)
  17. {
  18. if(str[l] == str[r])
  19. {
  20. ans+=;
  21. l--;
  22. r++;
  23. }else break;
  24. }
  25. return ans;
  26. }
  27.  
  28. int search2(int pos)
  29. {
  30. int l, r, ans = ;
  31. l = pos;
  32. r = pos+;
  33. while(l >= && r < len)
  34. {
  35. if(str[l] == str[r])
  36. {
  37. ans+=;
  38. l--;
  39. r++;
  40. }else break;
  41. }
  42. return ans;
  43. }
  44.  
  45. int main()
  46. {
  47. while(getline(cin, str))
  48. {
  49. len = str.length();
  50. int ans = , tmp;
  51. for(int i = ; i < len; i++)
  52. {
  53. tmp = search(i);
  54. if(tmp>ans)ans = tmp;
  55. tmp = search2(i);
  56. if(tmp>ans)ans = tmp;
  57. }
  58. cout<<ans<<endl;
  59. }
  60.  
  61. return ;
  62. }

L2-009. 抢红包

没有人没抢过红包吧…… 这里给出N个人之间互相发红包、抢红包的记录,请你统计一下他们抢红包的收获。

输入格式:

输入第一行给出一个正整数N(<= 104),即参与发红包和抢红包的总人数,则这些人从1到N编号。随后N行,第i行给出编号为i的人发红包的记录,格式如下:

K N1 P1 ... NK PK

其中K(0 <= K <= 20)是发出去的红包个数,Ni是抢到红包的人的编号,Pi(> 0)是其抢到的红包金额(以分为单位)。注意:对于同一个人发出的红包,每人最多只能抢1次,不能重复抢。

输出格式:

按照收入金额从高到低的递减顺序输出每个人的编号和收入金额(以元为单位,输出小数点后2位)。每个人的信息占一行,两数字间有1个空格。如果收入金额有并列,则按抢到红包的个数递减输出;如果还有并列,则按个人编号递增输出。

输入样例:

  1. 10
  2. 3 2 22 10 58 8 125
  3. 5 1 345 3 211 5 233 7 13 8 101
  4. 1 7 8800
  5. 2 1 1000 2 1000
  6. 2 4 250 10 320
  7. 6 5 11 9 22 8 33 7 44 10 55 4 2
  8. 1 3 8800
  9. 2 1 23 2 123
  10. 1 8 250
  11. 4 2 121 4 516 7 112 9 10

输出样例:

  1. 1 11.63
  2. 2 3.63
  3. 8 3.63
  4. 3 2.11
  5. 7 1.69
  6. 6 -1.67
  7. 9 -2.18
  8. 10 -3.26
  9. 5 -3.26
  10. 4 -12.32
  1. //2017-03-19
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. const int N = ;
  10. struct node{
  11. int id, cnt;
  12. double out, in;
  13. double fin;
  14. bool operator <(node x)
  15. {
  16. if(fin == x.fin)return cnt > x.cnt;
  17. return fin > x.fin;
  18. }
  19. }man[N];
  20.  
  21. int main()
  22. {
  23. int n, k;
  24. while(cin>>n)
  25. {
  26. for(int i = ; i <= n; i++)
  27. {
  28. man[i].in = ;
  29. man[i].out = ;
  30. man[i].cnt = ;
  31. }
  32. for(int i = ; i <= n; i++)
  33. {
  34. man[i].id = i;
  35. cin>>k;
  36. int id, monky;
  37. while(k--)
  38. {
  39. cin>>id>>monky;
  40. man[id].in += monky;
  41. man[i].out += monky;
  42. man[id].cnt++;
  43. }
  44. }
  45. for(int i = ; i <= n; i++)
  46. man[i].fin = (man[i].in-man[i].out)/;
  47. sort(man+, man+n+);
  48. for(int i = ; i <= n; i++)
  49. printf("%d %.2lf\n", man[i].id, man[i].fin);
  50. }
  51.  
  52. return ;
  53. }

L2-010. 排座位

布置宴席最微妙的事情,就是给前来参宴的各位宾客安排座位。无论如何,总不能把两个死对头排到同一张宴会桌旁!这个艰巨任务现在就交给你,对任何一对客人,请编写程序告诉主人他们是否能被安排同席。

输入格式:

输入第一行给出3个正整数:N(<= 100),即前来参宴的宾客总人数,则这些人从1到N编号;M为已知两两宾客之间的关系数;K为查询的条数。随后M行,每行给出一对宾客之间的关系,格式为:“宾客1 宾客2 关系”,其中“关系”为1表示是朋友,-1表示是死对头。注意两个人不可能既是朋友又是敌人。最后K行,每行给出一对需要查询的宾客编号。

这里假设朋友的朋友也是朋友。但敌人的敌人并不一定就是朋友,朋友的敌人也不一定是敌人。只有单纯直接的敌对关系才是绝对不能同席的。

输出格式:

对每个查询输出一行结果:如果两位宾客之间是朋友,且没有敌对关系,则输出“No problem”;如果他们之间并不是朋友,但也不敌对,则输出“OK”;如果他们之间有敌对,然而也有共同的朋友,则输出“OK but...”;如果他们之间只有敌对关系,则输出“No way”。

输入样例:

  1. 7 8 4
  2. 5 6 1
  3. 2 7 -1
  4. 1 3 1
  5. 3 4 1
  6. 6 7 -1
  7. 1 2 1
  8. 1 4 1
  9. 2 3 -1
  10. 3 4
  11. 5 7
  12. 2 3
  13. 7 2

输出样例:

  1. No problem
  2. OK
  3. OK but...
  4. No way
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. int G[][];
  8. int n;
  9.  
  10. void query(int a, int b)
  11. {
  12. if(G[a][b] == ){
  13. for(int i = ; i <= n; i++)
  14. if(G[a][i] == && G[b][i] == ){
  15. cout<<"No problem"<<endl;
  16. return;
  17. }
  18. cout<<"OK"<<endl;
  19. }else if(G[a][b] == ){
  20. for(int i = ; i <= n; i++)
  21. if(G[a][i] == - && G[b][i] == -)
  22. return;
  23. cout<<"No problem"<<endl;
  24. }else if(G[a][b] == -){
  25. for(int i = ; i <= n; i++)
  26. if(G[a][i] == && G[b][i] == ){
  27. cout<<"OK but..."<<endl;
  28. return;
  29. }
  30. cout<<"No way"<<endl;
  31. }
  32. }
  33.  
  34. int main()
  35. {
  36. int m, q, u, v, re;
  37. while(cin>>n>>m>>q)
  38. {
  39. memset(G, , sizeof(G));
  40. for(int i = ; i < m; i++)
  41. {
  42. cin>>u>>v>>re;
  43. G[u][v] = G[v][u] = re;
  44. }
  45. while(q--)
  46. {
  47. cin>>u>>v;
  48. query(u, v);
  49. }
  50. }
  51.  
  52. return ;
  53. }

L2-011. 玩转二叉树

给定一棵二叉树的中序遍历和前序遍历,请你先将树做个镜面反转,再输出反转后的层序遍历的序列。所谓镜面反转,是指将所有非叶结点的左右孩子对换。这里假设键值都是互不相等的正整数。

输入格式:

输入第一行给出一个正整数N(<=30),是二叉树中结点的个数。第二行给出其中序遍历序列。第三行给出其前序遍历序列。数字间以空格分隔。

输出格式:

在一行中输出该树反转后的层序遍历的序列。数字间以1个空格分隔,行首尾不得有多余空格。

输入样例:

  1. 7
  2. 1 2 3 4 5 6 7
  3. 4 1 3 2 6 5 7

输出样例:

  1. 4 6 1 7 5 3 2
  1. //2017-03-20
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <queue>
  6.  
  7. using namespace std;
  8.  
  9. int pre[], in[], ANS[];
  10. struct node{
  11. int data;
  12. node *lson, *rson;
  13. node(int d):data(d), lson(NULL), rson(NULL){}
  14. };
  15.  
  16. struct BT{
  17. node *root;
  18. void rebuild(int n)
  19. {
  20. root = buildTree(pre, in, n);
  21. }
  22. node* buildTree(int *pre, int *in, int n)
  23. {
  24. if(n < )return NULL;
  25. node *rt = new node(pre[]);
  26. if(n == )return rt;
  27. int R;
  28. for(int i = ; i < n; i++)
  29. {
  30. if(in[i] == pre[]){
  31. R = i;
  32. break;
  33. }
  34. }
  35. rt->lson = buildTree(pre+, in, R);
  36. rt->rson = buildTree(pre++R, in+R+, n-R-);
  37. return rt;
  38. }
  39. void levelOrder()
  40. {
  41. queue<node*> q;
  42. q.push(root);
  43. node *h;
  44. int cnt = ;
  45. while(!q.empty()){
  46. h = q.front();
  47. q.pop();
  48. ANS[cnt++] = h->data;
  49. if(h->rson)q.push(h->rson);
  50. if(h->lson)q.push(h->lson);
  51. }
  52. for(int i = ; i < cnt; i++)
  53. if(i == cnt-)cout<<ANS[i]<<endl;
  54. else cout<<ANS[i]<<" ";
  55. }
  56. };
  57.  
  58. int main()
  59. {
  60. int n;
  61. while(cin>>n)
  62. {
  63. for(int i = ; i < n; i++)
  64. cin>>in[i];
  65. for(int i = ; i < n; i++)
  66. cin>>pre[i];
  67. BT bt;
  68. bt.rebuild(n);
  69. bt.levelOrder();
  70. }
  71.  
  72. return ;
  73. }

L2-012. 关于堆的判断

将一系列给定数字顺序插入一个初始为空的小顶堆H[]。随后判断一系列相关命题是否为真。命题分下列几种:
  • “x is the root”:x是根结点;
  • “x and y are siblings”:x和y是兄弟结点;
  • “x is the parent of y”:x是y的父结点;
  • “x is a child of y”:x是y的一个子结点。

输入格式:

每组测试第1行包含2个正整数N(<= 1000)和M(<= 20),分别是插入元素的个数、以及需要判断的命题数。下一行给出区间[-10000, 10000]内的N个要被插入一个初始为空的小顶堆的整数。之后M行,每行给出一个命题。题目保证命题中的结点键值都是存在的。

输出格式:

对输入的每个命题,如果其为真,则在一行中输出“T”,否则输出“F”。

输入样例:

  1. 5 4
  2. 46 23 26 24 10
  3. 24 is the root
  4. 26 and 23 are siblings
  5. 46 is the parent of 23
  6. 23 is a child of 10

输出样例:

  1. F
  2. T
  3. F
  4. T
  1. //2017-03-20
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. struct Heap{
  9. int h[];
  10. int n;
  11. void init()
  12. {
  13. n = ;
  14. }
  15. void shiftup(int pos)
  16. {
  17. int fa, tmp;
  18. while(pos >= ){
  19. fa = (pos-)/;
  20. if(h[fa]>h[pos]){
  21. tmp = h[pos];
  22. h[pos] = h[fa];
  23. h[fa] = tmp;
  24. pos = fa;
  25. }else break;
  26. }
  27. }
  28. void addNode(int x)
  29. {
  30. h[n++] = x;
  31. shiftup(n-);
  32. }
  33. void show(){
  34. for(int i = ; i < n; i++)
  35. cout<<h[i]<<" ";
  36. cout<<endl;
  37. }
  38. };
  39.  
  40. int main()
  41. {
  42. int n,m;
  43. while(cin>>n>>m)
  44. {
  45. Heap heap;
  46. heap.init();
  47. int a;
  48. for(int i = ; i < n; i++)
  49. {
  50. cin>>a;
  51. heap.addNode(a);
  52. }
  53. int x, y;
  54. string s1, s2, s3, s4;
  55. while(m--)
  56. {
  57. cin>>x;
  58. cin>>s1;
  59. if(s1[] == 'a'){
  60. cin>>y>>s2>>s3;
  61. int p1, p2;
  62. for(int i = ; i < heap.n; i++)
  63. {
  64. if(heap.h[i] == x)p1 = i;
  65. if(heap.h[i] == y)p2 = i;
  66. }
  67. if((p1-)/ == (p2-)/)cout<<"T"<<endl;
  68. else cout<<"F"<<endl;
  69. }else{
  70. cin>>s2;
  71. if(s2[] == 'a'){
  72. cin>>s3>>s4>>y;
  73. int p1, p2;
  74. for(int i = ; i < heap.n; i++)
  75. {
  76. if(heap.h[i] == x)p1 = i;
  77. if(heap.h[i] == y)p2 = i;
  78. }
  79. if((p1-)/ == p2)cout<<"T"<<endl;
  80. else cout<<"F"<<endl;
  81. }else{
  82. cin>>s3;
  83. if(s3[] == 'r'){
  84. if(heap.h[] == x)cout<<"T"<<endl;
  85. else cout<<"F"<<endl;
  86. }else{
  87. cin>>s4>>y;
  88. int p1, p2;
  89. for(int i = ; i < heap.n; i++){
  90. if(heap.h[i] == x)p1 = i;
  91. if(heap.h[i] == y)p2 = i;
  92. }
  93. if((p2-)/ == p1)cout<<"T"<<endl;
  94. else cout<<"F"<<endl;
  95. }
  96. }
  97. }
  98. }
  99. }
  100.  
  101. return ;
  102. }

L2-017. 人以群分

社交网络中我们给每个人定义了一个“活跃度”,现希望根据这个指标把人群分为两大类,即外向型(outgoing,即活跃度高的)和内向型(introverted,即活跃度低的)。要求两类人群的规模尽可能接近,而他们的总活跃度差距尽可能拉开。

输入格式:

输入第一行给出一个正整数N(2 <= N <= 105)。随后一行给出N个正整数,分别是每个人的活跃度,其间以空格分隔。题目保证这些数字以及它们的和都不会超过231

输出格式:

按下列格式输出:

  1. Outgoing #: N1
  2. Introverted #: N2
  3. Diff = N3

其中 N1 是外向型人的个数;N2 是内向型人的个数;N3 是两群人总活跃度之差的绝对值。

输入样例1:

  1. 10
  2. 23 8 10 99 46 2333 46 1 666 555

输出样例1:

  1. Outgoing #: 5
  2. Introverted #: 5
  3. Diff = 3611

输入样例2:

  1. 13
  2. 110 79 218 69 3721 100 29 135 2 6 13 5188 85

输出样例2:

  1. Outgoing #: 7
  2. Introverted #: 6
  3. Diff = 9359
  1. //2018-03-14
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <iostream>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. const int N = ;
  10. int arr[N];
  11.  
  12. int main()
  13. {
  14. int n;
  15. while(~scanf("%d", &n)){
  16. for(int i = ; i < n; i++)
  17. scanf("%d", &arr[i]);
  18. sort(arr, arr+n);
  19. int in = n/;
  20. int sumIn = , sumOut = ;
  21. for(int i= ; i < n; i++){
  22. if(i < in) sumIn += arr[i];
  23. else sumOut += arr[i];
  24. }
  25. printf("Outgoing #: %d\nIntroverted #: %d\nDiff = %d\n", n-in, in, sumOut-sumIn);
  26. }
  27.  
  28. return ;
  29. }

L2-019. 悄悄关注

新浪微博上有个“悄悄关注”,一个用户悄悄关注的人,不出现在这个用户的关注列表上,但系统会推送其悄悄关注的人发表的微博给该用户。现在我们来做一回网络侦探,根据某人的关注列表和其对其他用户的点赞情况,扒出有可能被其悄悄关注的人。

输入格式:

输入首先在第一行给出某用户的关注列表,格式如下:

人数N 用户1 用户2 …… 用户N

其中N是不超过5000的正整数,每个“用户i”(i=1, ..., N)是被其关注的用户的ID,是长度为4位的由数字和英文字母组成的字符串,各项间以空格分隔。

之后给出该用户点赞的信息:首先给出一个不超过10000的正整数M,随后M行,每行给出一个被其点赞的用户ID和对该用户的点赞次数(不超过1000),以空格分隔。注意:用户ID是一个用户的唯一身份标识。题目保证在关注列表中没有重复用户,在点赞信息中也没有重复用户。

输出格式:

我们认为被该用户点赞次数大于其点赞平均数、且不在其关注列表上的人,很可能是其悄悄关注的人。根据这个假设,请你按用户ID字母序的升序输出可能是其悄悄关注的人,每行1个ID。如果其实并没有这样的人,则输出“Bing Mei You”。

输入样例1:

  1. 10 GAO3 Magi Zha1 Sen1 Quan FaMK LSum Eins FatM LLao
  2. 8
  3. Magi 50
  4. Pota 30
  5. LLao 3
  6. Ammy 48
  7. Dave 15
  8. GAO3 31
  9. Zoro 1
  10. Cath 60

输出样例1:

  1. Ammy
  2. Cath
  3. Pota

输入样例2:

  1. 11 GAO3 Magi Zha1 Sen1 Quan FaMK LSum Eins FatM LLao Pota
  2. 7
  3. Magi 50
  4. Pota 30
  5. LLao 48
  6. Ammy 3
  7. Dave 15
  8. GAO3 31
  9. Zoro 29

输出样例2:

  1. Bing Mei You
  1. //2018-03-14
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <set>
  7.  
  8. using namespace std;
  9.  
  10. const int N = ;
  11.  
  12. string strs[*N];
  13. int arr[*N];
  14. set<string> st, ans_st;
  15.  
  16. int main()
  17. {
  18. int n, m;
  19. while(cin>>n){
  20. string str;
  21. st.clear();
  22. for(int i = ; i < n; i++){
  23. cin>>str;
  24. st.insert(str);
  25. }
  26. cin>>m;
  27. int sum = ;
  28. for(int i = ; i < m; i++){
  29. cin>>strs[i]>>arr[i];
  30. sum += arr[i];
  31. }
  32. double avg = 1.0*sum/m;
  33. set<string>::iterator iter;
  34. ans_st.clear();
  35. for(int i = ; i < m; i++){
  36. if((iter = st.find(strs[i])) == st.end() && arr[i] > avg){
  37. ans_st.insert(strs[i]);
  38. }
  39. }
  40. if(ans_st.empty()){
  41. cout<<"Bing Mei You"<<endl;
  42. }else{
  43. for(auto x: ans_st){
  44. cout<<x<<endl;
  45. }
  46. }
  47. }
  48.  
  49. return ;
  50. }

L2-020. 功夫传人

一门武功能否传承久远并被发扬光大,是要看缘分的。一般来说,师傅传授给徒弟的武功总要打个折扣,于是越往后传,弟子们的功夫就越弱…… 直到某一支的某一代突然出现一个天分特别高的弟子(或者是吃到了灵丹、挖到了特别的秘笈),会将功夫的威力一下子放大N倍 —— 我们称这种弟子为“得道者”。

这里我们来考察某一位祖师爷门下的徒子徒孙家谱:假设家谱中的每个人只有1位师傅(除了祖师爷没有师傅);每位师傅可以带很多徒弟;并且假设辈分严格有序,即祖师爷这门武功的每个第i代传人只能在第i-1代传人中拜1个师傅。我们假设已知祖师爷的功力值为Z,每向下传承一代,就会减弱r%,除非某一代弟子得道。现给出师门谱系关系,要求你算出所有得道者的功力总值。

输入格式:

输入在第一行给出3个正整数,分别是:N(<=105)——整个师门的总人数(于是每个人从0到N-1编号,祖师爷的编号为0);Z——祖师爷的功力值(不一定是整数,但起码是正数);r ——每传一代功夫所打的折扣百分比值(不超过100的正数)。接下来有N行,第i行(i=0, ..., N-1)描述编号为i的人所传的徒弟,格式为:

Ki ID[1] ID[2] ... ID[Ki]

其中Ki是徒弟的个数,后面跟的是各位徒弟的编号,数字间以空格间隔。Ki为零表示这是一位得道者,这时后面跟的一个数字表示其武功被放大的倍数。

输出格式:

在一行中输出所有得道者的功力总值,只保留其整数部分。题目保证输入和正确的输出都不超过1010

输入样例:

  1. 10 18.0 1.00
  2. 3 2 3 5
  3. 1 9
  4. 1 4
  5. 1 7
  6. 0 7
  7. 2 6 1
  8. 1 8
  9. 0 9
  10. 0 4
  11. 0 3

输出样例:

  1. 404
  1. //2018-03-15
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9.  
  10. const int N = ;
  11. int fa[N], dd_id[N], dd_bs[N], depth[N];
  12.  
  13. int getDepth(int x){
  14. if(fa[x] == x)return ;
  15. if(depth[x])return depth[x];
  16. return depth[x] = getDepth(fa[x])+;
  17. }
  18.  
  19. int main()
  20. {
  21. int n, k;
  22. double Z, r;
  23. while(cin>>n>>Z>>r){
  24. r = (-r)/;
  25. int cnt = , tmp;
  26. memset(depth, , sizeof(depth));
  27. for(int i = ; i < n; i++)
  28. fa[i] = i;
  29. for(int i = ; i < n; i++){
  30. cin >> k;
  31. if(!k){
  32. cin>>tmp;
  33. dd_id[cnt] = i;
  34. dd_bs[cnt++] = tmp;
  35. }else{
  36. while(k--){
  37. cin>>tmp;
  38. fa[tmp] = i;
  39. }
  40. }
  41. }
  42. double sum = ;
  43. for(int i = ; i < cnt; i++){
  44. double dsum = Z*dd_bs[i];
  45. int dp = getDepth(dd_id[i]);
  46. dsum *= pow(r, dp);
  47. sum += dsum;
  48. }
  49. cout<<(int)sum<<endl;
  50. }
  51.  
  52. return ;
  53. }

L2-021. 点赞狂魔

微博上有个“点赞”功能,你可以为你喜欢的博文点个赞表示支持。每篇博文都有一些刻画其特性的标签,而你点赞的博文的类型,也间接刻画了你的特性。然而有这么一种人,他们会通过给自己看到的一切内容点赞来狂刷存在感,这种人就被称为“点赞狂魔”。他们点赞的标签非常分散,无法体现出明显的特性。本题就要求你写个程序,通过统计每个人点赞的不同标签的数量,找出前3名点赞狂魔。

输入格式:

输入在第一行给出一个正整数N(<=100),是待统计的用户数。随后N行,每行列出一位用户的点赞标签。格式为“Name K F1 ... FK”,其中 Name 是不超过8个英文小写字母的非空用户名,1<=K<=1000,Fi(i=1, ..., K)是特性标签的编号,我们将所有特性标签从1到107编号。数字间以空格分隔。

输出格式:

统计每个人点赞的不同标签的数量,找出数量最大的前3名,在一行中顺序输出他们的用户名,其间以1个空格分隔,且行末不得有多余空格。如果有并列,则输出标签出现次数平均值最小的那个,题目保证这样的用户没有并列。若不足3人,则用“-”补齐缺失,例如“mike jenny -”就表示只有2人。

输入样例:

  1. 5
  2. bob 11 101 102 103 104 105 106 107 108 108 107 107
  3. peter 8 1 2 3 4 3 2 5 1
  4. chris 12 1 2 3 4 5 6 7 8 9 1 2 3
  5. john 10 8 7 6 5 4 3 2 1 7 5
  6. jack 9 6 7 8 9 10 11 12 13 14

输出样例:

  1. jack chris john
  1. //2018-03-15
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <iostream>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. const int N = ;
  10.  
  11. struct Node{
  12. string name;
  13. int len, uniLen;
  14.  
  15. bool operator<(Node node){
  16. if(uniLen == node.uniLen)
  17. return len < node.len;
  18. return uniLen > node.uniLen;
  19. }
  20. }person[N];
  21.  
  22. int arr[];
  23.  
  24. int main()
  25. {
  26. int n;
  27. while(cin >> n){
  28. string str;
  29. for(int i = ; i < n; i++){
  30. cin>>person[i].name>>person[i].len;
  31. for(int j = ; j < person[i].len; j++)
  32. scanf("%d", &arr[j]);
  33. sort(arr, arr+person[i].len);
  34. int cnt = unique(arr, arr+person[i].len) - arr;
  35. person[i].uniLen = cnt;
  36. }
  37. sort(person, person+n);
  38. if(n == )cout<<"- - -"<<endl;
  39. else if(n == )cout<<person[].name<<" - -"<<endl;
  40. else if(n == )cout<<person[].name<<" "<<person[].name<<" -"<<endl;
  41. else cout<<person[].name<<" "<<person[].name<<" "<<person[].name<<endl;
  42. }
  43.  
  44. return ;
  45. }

L3-001. 凑零钱

韩梅梅喜欢满宇宙到处逛街。现在她逛到了一家火星店里,发现这家店有个特别的规矩:你可以用任何星球的硬币付钱,但是绝不找零,当然也不能欠债。韩梅梅手边有104枚来自各个星球的硬币,需要请你帮她盘算一下,是否可能精确凑出要付的款额。

输入格式:

输入第一行给出两个正整数:N(<=104)是硬币的总个数,M(<=102)是韩梅梅要付的款额。第二行给出N枚硬币的正整数面值。数字间以空格分隔。

输出格式:

在一行中输出硬币的面值 V1 <= V2 <= ... <= Vk,满足条件 V1 + V2 + ... + Vk = M。数字间以1个空格分隔,行首尾不得有多余空格。若解不唯一,则输出最小序列。若无解,则输出“No Solution”。

注:我们说序列{A[1], A[2], ...}比{B[1], B[2], ...}“小”,是指存在 k >= 1 使得 A[i]=B[i] 对所有 i < k 成立,并且 A[k] < B[k]。

输入样例1:

  1. 8 9
  2. 5 9 8 7 2 3 4 1

输出样例1:

  1. 1 3 5

输入样例2:

  1. 4 8
  2. 7 2 4 3

输出样例2:

  1. No Solution
  1. //2018-03-15
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. const int N = ;
  10. int arr[N], book[N], suffix_sum[N];//后缀和
  11. int n, m;
  12. bool ok;
  13.  
  14. void dfs(int step, int money){
  15. //剪枝
  16. if(step > n || ok || money > m || money+suffix_sum[step] < m)return;
  17. if(money == m){
  18. ok = true;
  19. bool first = true;
  20. for(int i = ; i < n; i++){
  21. if(book[i]){
  22. if(first){
  23. printf("%d", arr[i]);
  24. first = false;
  25. }else{
  26. printf(" %d", arr[i]);
  27. }
  28. }
  29. }
  30. printf("\n");
  31. }
  32. book[step] = ;
  33. dfs(step+, money+arr[step]);
  34. book[step] = ;
  35. dfs(step+, money);
  36. }
  37.  
  38. int main()
  39. {
  40. while(~scanf("%d%d", &n, &m))
  41. {
  42. for(int i = ; i < n; i++)
  43. scanf("%d", &arr[i]);
  44. sort(arr, arr+n);
  45. suffix_sum[n] = ;
  46. for(int i = n-; i >= ; i--)
  47. suffix_sum[i] = suffix_sum[i+]+arr[i];
  48. ok = false;
  49. memset(book, , sizeof(book));
  50. dfs(, );
  51. if(!ok)printf("No Solution\n");
  52. }
  53.  
  54. return ;
  55. }

天梯赛2016-L2的更多相关文章

  1. 第四届CCCC团体程序设计天梯赛 后记

    一不小心又翻车了,第二次痛失200分 1.开局7分钟A了L2-3,一看榜已经有七个大兄弟排在前面了,翻车 * 1 2.把L1-3 A了18分,留了两分准备抢顽强拼搏奖,最后五秒钟把题过了,万万没想到还 ...

  2. 团体程序设计天梯赛(CCCC) L3009 长城 方法证明

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  3. 【CCCC天梯赛决赛】

    cccc的天梯赛决赛,水题一样的水,中档题以上的还是没做出来.补了一下题,觉得其实也不是很难,主要是练的少. L2-1:红色预警 并查集 我做的时候想不到并查集,想到了也不一定做的出来,都是其实不难. ...

  4. 记第一届 CCCC-团体程序设计天梯赛决赛 参赛

    其他都没什么,上午报道,下午比赛两个半小时,最后139分 但四我超遗憾的是,最后在做L3-1二叉搜索树,因为看到有辣么多人做出来,可是我没做出来啊 比赛结束后看了看其他两道当场吐血,L3-3直捣黄龙不 ...

  5. L1-049 天梯赛座位分配​​​​​​​

    L1-049 天梯赛座位分配 (20 分) 天梯赛每年有大量参赛队员,要保证同一所学校的所有队员都不能相邻,分配座位就成为一件比较麻烦的事情.为此我们制定如下策略:假设某赛场有 N 所学校参赛,第 i ...

  6. 团体程序设计天梯赛(CCCC) L3021 神坛 的一些错误做法(目前网上的方法没一个是对的) 和 一些想法

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  7. 团体程序设计天梯赛(CCCC) L3019 代码排版 方法与编译原理密切相关,只有一个测试点段错误

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  8. 团体程序设计天梯赛(CCCC) L3015 球队“食物链” 状态压缩

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code #include <cstdio> #include ...

  9. 团体程序设计天梯赛(CCCC) L3014 周游世界 BFS证明

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  10. 团体程序设计天梯赛(CCCC) L3013 非常弹的球 不同思路

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

随机推荐

  1. Nmap命令的常用实例

    一.Nmap简介 nmap是一个网络连接端扫描软件,用来扫描网上电脑开放的网络连接端.确定哪些服务运行在哪些连接端,并且推断计算机运行哪个操作系统(这是亦称 fingerprinting).它是网络管 ...

  2. 初识node.js(通过npm下载项目依赖的包的过程)

    一.初识node.js 简单的说Node.js 就是运行在服务器端的JavaScript. Node.js 是一个基于Chrome JavaScript 运行时建立的一个平台. Node.js是一个事 ...

  3. mybatis-spring集成:配置多数据库源中遇到的问题

    转自:http://www.cfanz.cn/index.php?c=article&a=read&id=71583 mybatis配置多数据源本身很简单,和基本配置差别不大 但是如果 ...

  4. [ActionScript 3.0] 加载子swf需要指定应用程序域

    var ldr:Loader = new Loader(); ldr.load(new URLRequest("assets/test.swf")); 如上,如果在flash帧上写 ...

  5. D16——C语言基础学PYTHON

    C语言基础学习PYTHON——基础学习D16 20180927内容纲要: 1.JavaScript介绍 2.JavaScript功能介绍 3.JavaScript变量 4.Dom操作 a.获取标签 b ...

  6. sql server always on安装

    always on 是sql server 服务器的数据同步备份容灾工具, 集中了故障转移群集.数据库镜像和日志传送等功能. 环境: window server 2012 sql server 201 ...

  7. Executor框架(一)

    类继承关系 更详细的继承关系: ExecutorComplitionService类 在说Executor接口及实现类之前,先聊聊ExecutorComplitionService. 成员变量 pri ...

  8. PHP多进程系列笔记(三)

    本节讲解几个多进程的实例. 多进程实例 Master-Worker结构 下面例子实现了简单的多进程管理: 支持设置最大子进程数 Master-Worker结构:Worker挂掉,Master进程会重新 ...

  9. 代码高亮插件——wangHightLighter.js——demo演示

    wangHighLighter.js demo 语言:   主题: 转换   说明: wangHightLighter.js是一个可以将代码高亮显示的javascript小插件,支持常用的20多语言. ...

  10. Redis+Jedis封装工具类

    package com.liying.monkey.core.util; import java.io.IOException; import java.util.ArrayList; import ...