[关闭]
@darkproject 2016-12-08T13:27:46.000000Z 字数 1963 阅读 842

集训队第一次作业题

作业


A Design Tutorial: Learn from Math

本来打算合数筛选判断的,后来猜了下居然A啦qwq

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int n, x, y;
  6. cin >> n;
  7. if (n % 2 == 0) cout << "4 " << n - 4 << endl;
  8. else cout << "9 " << n - 9 << endl;
  9. return 0;
  10. }

B Design Tutorial: Learn from Life

贪心,排序后从高处开始,每次拉k人,遇到需要停下的人就把他们放下,然后继续运输

  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4. int a[2005];
  5. int main()
  6. {
  7. int n, k, ans = 0;
  8. cin >> n >> k;
  9. for (int i = 1; i <= n; ++i) cin >> a[i];
  10. sort(a+1,a + n+1);
  11. for (int i = n; i > 0; i -= k)
  12. ans += 2 * a[i] - 2;
  13. cout << ans << endl;
  14. return 0;
  15. }

C Design Tutorial: Make It Nondeterministic

给出一个人的两个名字,选择其中一个,让所有人名序列满足字典序,
第一个输入数据取最短,然后与第二个数据最短比较,不符与第二个数据最长比较,还不符就GG,符合继续比较第三个。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. struct {
  4. string f;
  5. string l;
  6. }str[100005];
  7. int num[100005];
  8. bool flag = true;
  9. int main()
  10. {
  11. int n;
  12. cin >> n;
  13. for (int i = 1; i <= n; ++i) cin >> str[i].f>>str[i].l;
  14. for (int i = 1; i <= n; ++i) cin >> num[i];
  15. string now = min(str[num[1]].f, str[num[1]].l);
  16. for (int i = 2; i <= n; ++i)
  17. {
  18. string temp = min(str[num[i]].f, str[num[i]].l);
  19. if (now >= temp)
  20. {
  21. temp = max(str[num[i]].f, str[num[i]].l);
  22. if (now >= temp)
  23. {
  24. flag = false;
  25. break;
  26. }
  27. now = temp;
  28. }
  29. else now = temp;
  30. }
  31. if (flag)
  32. cout << "YES" << endl;
  33. else
  34. cout << "NO" << endl;
  35. return 0;
  36. }

F MUH and Important Things

n个任务,每个任务有难度值,在保证难度值优先最小的情况下,得到序列是否有3.排序然后遇到相当难度值考虑多情况交换

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cstdio>
  4. using namespace std;
  5. struct arr{
  6. int number;
  7. int value;
  8. }data1[2005];
  9. bool cmp(const arr &a, const arr &b)
  10. {
  11. return a.value < b.value;
  12. }
  13. int main()
  14. {
  15. int n, num = 0;
  16. cin >> n;
  17. for (int i = 1; i <= n; ++i)
  18. {
  19. cin >> data1[i].value;
  20. data1[i].number = i;
  21. }
  22. sort(data1 + 1, data1 + n + 1, cmp);
  23. for (int i = 1; i <= n - 1; ++i)
  24. if (data1[i].value == data1[i + 1].value) num++;
  25. if (num<2) {
  26. cout << "NO" << endl;
  27. return 0;
  28. }
  29. else
  30. {
  31. cout << "YES" << endl;
  32. for (int t = 0; t < 3; t++)
  33. {
  34. for (int i = 1; i <= n; i++)
  35. printf("%d ", data1[i].number);
  36. printf("\n");
  37. for (int i = 1; i < n; i++)
  38. {
  39. if (data1[i].value == data1[i + 1].value && data1[i].number < data1[i + 1].number)
  40. {
  41. swap(data1[i], data1[i + 1]);
  42. break;
  43. }
  44. }
  45. }
  46. }
  47. return 0;
  48. }

I - George and Accommodation

qwq

  1. #include<iostream>
  2. #include<cstdio>
  3. using namespace std;
  4. int n,m;
  5. int main()
  6. {
  7. scanf("%d",&n);
  8. int x,y;
  9. for(int i=1;i<=n;i++)
  10. {
  11. scanf("%d%d",&x,&y);
  12. if(y-x>=2)
  13. m++;
  14. }
  15. printf("%d",m);
  16. return 0;
  17. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注