A:Rewards:

题目链接:http://codeforces.com/problemset/problem/448/A

题意:Bizon有a1个一等奖奖杯,a2个二等奖奖杯,a3个三等奖奖杯,b1个一等奖奖牌,b2个二等奖奖牌,b3个三等奖奖牌,和一个有n个架子的橱柜。如今Bizon想把这些奖牌和奖杯放在橱柜里,可是要遵循以下的规则:一个架子上不能同一时候放奖杯和奖牌;一个架子上的奖杯数量不能超过5个。奖牌数量不能超过10个。

问能不能把这些奖杯和奖牌所有放进去。

分析:依照贪心原则。一个架子上放尽可能多的奖杯和奖牌,求出须要多少个架子,与n比較大小就可以。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<iostream>
  5. #include<cstdlib>
  6. #include<algorithm>
  7. using namespace std;
  8. int main()
  9. {
  10. int a1, a2, a3, b1, b2, b3, n;
  11. while(~scanf("%d%d%d%d%d%d%d",&a1, &a2, &a3, &b1, &b2, &b3, &n))
  12. {
  13. int suma = a1 + a2 + a3;
  14. int sumb = b1 + b2 + b3;
  15. int cnta = suma / 5, cntb = sumb / 10;
  16. if(suma % 5 != 0)
  17. cnta++;
  18. if(sumb % 10 != 0)
  19. cntb++;
  20. if(cnta + cntb <= n)
  21. printf("YES\n");
  22. else
  23. printf("NO\n");
  24. }
  25. return 0;
  26. }

B:Suffix Structures

题目链接:http://codeforces.com/problemset/problem/448/B

题意:给出两个串s和t,问能不能把s变成t,假设能够,输出变换时用的数据结构是什么?变换时能够使用两种数据结构:1.suffix
automaton,它能够删除串中的随意一个字符。2.suffix array,它能够交换串中的随意两个字符。

假设仅仅用到suffix
automaton,输出“automaton“;假设仅仅用到”suffix array“,输出”array“;假设两种都用到,输出”both“;假设变不成。输出“need
tree”。

分析:直接模拟就可以。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<iostream>
  5. #include<string>
  6. #include<cstdlib>
  7. #include<algorithm>
  8. using namespace std;
  9. int main()
  10. {
  11. string s, t;
  12. int a[30], b[30];
  13. while(cin >> s >> t)
  14. {
  15. memset(a, 0, sizeof(a));
  16. memset(b, 0, sizeof(b));
  17. if(s.length() < t.length())
  18. {
  19. cout << "need tree" << endl;
  20. continue;
  21. }
  22. int ls = s.length(), lt = t.length();
  23. if(ls == lt)
  24. {
  25. for(int i = 0; i < ls; i++)
  26. {
  27. a[s[i] - 'a']++;
  28. b[t[i] - 'a']++;
  29. }
  30. int flag = 1;
  31. for(int i = 0; i < 26; i++)
  32. if(a[i] != b[i])
  33. {
  34. flag = 0;
  35. break;
  36. }
  37. if(flag)
  38. cout << "array" << endl;
  39. else
  40. cout << "need tree" << endl;
  41. }
  42. else
  43. {
  44. //cout << "s = " << s << ", t = " << t << endl;
  45. for(int i = 0; i < ls; i++)
  46. a[s[i] - 'a']++;
  47. for(int i = 0; i < lt; i++)
  48. b[t[i] - 'a']++;
  49. int flag = 1, ok = 0;
  50. for(int i = 0; i < 26; i++)
  51. if(a[i] < b[i])
  52. {
  53. flag = 0;
  54. break;
  55. }
  56. if(flag)
  57. {
  58. int j, k = 0;
  59. for(int i = 0; i < ls; i++)
  60. {
  61. if(s[i] == t[k])
  62. k++;
  63. if(k == lt)
  64. {
  65. ok = 1;
  66. break;
  67. }
  68. } //t中的字符在s中不一定连续出现,比如ababa abb,应是 aruomaton。比赛时一直Wa在这。
  69.  
  70. }
  71. if(flag && ok)
  72. cout << "automaton" << endl;
  73. else if(flag && !ok)
  74. cout << "both" << endl;
  75. else
  76. cout << "need tree" << endl;
  77. }
  78. }
  79. return 0;
  80. }

C.Painting Fence

题目链接:http://codeforces.com/problemset/problem/448/C

题意:Bizon要粉刷他的栅栏。栅栏由n块木板组成,每一块有个高度,每次stroke时必须一直接触着栅栏。问最少须要stroke多少次,能够把栅栏刷好。

分析:分治法。

把栅栏从最低处分成左右两部分,每一部分再这样分下去,直到仅仅剩下一块木板。然后往上返回最小值就可以。

  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. const int MAXN = 5005;
  5. int a[MAXN];
  6. int solve(int l, int r, int h)
  7. {
  8. int k = l, mmin = a[l];
  9. if(l > r) return 0;
  10. if(l == r) return a[l] > h;
  11. for(int i = l; i <= r; i++)
  12. if(a[i] < mmin)
  13. {
  14. k = i;
  15. mmin = a[i];
  16. }
  17. return min(r-l+1, solve(l, k-1, mmin) + solve(k+1, r, mmin) + (mmin - h));
  18. }
  19. int main()
  20. {
  21. int n;
  22. scanf("%d",&n);
  23. for(int i = 0; i < n; i++)
  24. scanf("%d",&a[i]);
  25. printf("%d\n", solve(0, n-1, 0));
  26. return 0;
  27. }
  28.  
  29. #include<cstdio>
  30. #include<algorithm>
  31. using namespace std;
  32. const int MAXN = 5005;
  33. int a[MAXN];
  34. int solve(int l, int r)
  35. {
  36. int k = l;
  37. if(l > r) return 0;
  38. for(int i = l; i <= r; i++)
  39. if(a[i] < a[k])
  40. k = i;
  41. int tmp = a[k];
  42. for(int i = l; i <= r; i++)
  43. a[i] -= tmp;
  44. return min(r-l+1, solve(l, k-1) + solve(k+1, r) + tmp);
  45. }
  46. int main()
  47. {
  48. int n;
  49. scanf("%d",&n);
  50. for(int i = 0; i < n; i++)
  51. scanf("%d",&a[i]);
  52. printf("%d\n", solve(0, n-1));
  53. return 0;
  54. }

D:Multiplication Table

题目链接:http://codeforces.com/problemset/problem/448/D

题意:给出一个n行m列的乘法表,第i行第j列的值为i*j,把这些值从小到大排序,问第k个数是多少。

分析:二分。

  1. #include<iostream>
  2. using namespace std;
  3. typedef long long LL;
  4. LL solve(LL n, LL m, LL k)
  5. {
  6. LL l = 0, r = n * m;
  7. while(r - l > 1)
  8. {
  9. LL mid = (r + l) / 2;
  10. LL sum = 0;
  11. for(int i = 1; i <= n; i++)
  12. {
  13. LL tmp = mid / i;
  14. if(tmp > m) tmp = m;
  15. sum += tmp; //sum为不大于mid的值的个数
  16. }
  17. if(sum >= k) r = mid;
  18. else l = mid;
  19. }
  20. return r;
  21. }
  22. int main()
  23. {
  24. LL n, m, k;
  25. while(cin >> n >> m >> k)
  26. {
  27. cout << solve(n, m, k) << endl;
  28. }
  29. return 0;
  30. }

E:Divisors(dfs)

题目链接:http://codeforces.com/problemset/problem/448/E

题意:给出一个数n,把这个数的因子从小到大写出来,然后对这个数的因子运行k次同样的操作,问最后的结果是什么。假设结果超过100000位。仅仅输出前100000位。

分析:由于对每一个数运行的是同样的操作。所以能够用递归写,当运行到不能分解时,输出一个数,直到运行完k次或者个数已经达到了100000个结束。

  1. #include<iostream>
  2. #include<cmath>
  3. #include<algorithm>
  4. using namespace std;
  5. typedef __int64 LL;
  6. const int MAXN = 100000;
  7. LL divisor[MAXN], num;
  8. LL cnt = 0;
  9. void get_divisor(LL x)
  10. {
  11. num = 0;
  12. LL tmp = (LL)sqrt(x);
  13. for(int i = 1; i <= tmp; i++)
  14. {
  15. if(x % i == 0){
  16. divisor[num++] = i;
  17. if(x / i != i)
  18. divisor[num++] = x / i;
  19. }
  20. }
  21. sort(divisor, divisor + num);
  22. }
  23.  
  24. void dfs(LL x, LL k)
  25. {
  26. //cout << "x = " << x << ", k = " << k << endl;
  27. if(cnt >= 100000) return ;
  28. if(k == 0 || x == 1)
  29. {
  30. cout << x << " ";
  31. cnt++;
  32. return ;
  33. }
  34. for(LL i = 0; i < num && divisor[i] <= x; i++)
  35. {
  36. if(x % divisor[i] == 0) {
  37. dfs(divisor[i], k-1);
  38. if(cnt >= 100000) return ;
  39. }
  40. }
  41. }
  42.  
  43. int main()
  44. {
  45. LL x, k;
  46. while(cin >> x >> k)
  47. {
  48. get_divisor(x);
  49. dfs(x, k);
  50. cout << endl;
  51. }
  52. return 0;
  53. }

CodeForces 448的更多相关文章

  1. Codeforces #448 Div2 E

    #448 Div2 E 题意 给出一个数组,有两种类型操作: 选定不相交的两个区间,分别随机挑选一个数,交换位置. 查询区间和的期望. 分析 线段树区间更新区间求和. 既然是涉及到两个区间,那么对于第 ...

  2. Codeforces 448 D. Multiplication Table

    二分法判断答案 D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes inp ...

  3. Codeforces 448 E. Divisors (DFS,储存结构)

    题目链接:E. Divisors 题意: 给出一个X,f(X)是X所有约数的数列(例6:1 2 3 6),给出一个k,k是递归的次数(例:k=2 : f(f(X)) ; X=4,k=2: 1 1 2 ...

  4. Codeforces 448 D. Multiplication Table 二分

    题目链接:D. Multiplication Table 题意: 给出N×M的乘法矩阵要你求在这个惩罚矩阵中第k个小的元素(1 ≤ n, m ≤ 5·10^5; 1 ≤ k ≤ n·m). 题解: n ...

  5. Codeforces 448 C. Painting Fence

    递归.分治. . . C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input ...

  6. Codeforces Round #448 C. Square Subsets

    题目链接 Codeforces Round #448 C. Square Subsets 题解 质因数 *质因数 = 平方数,问题转化成求异或方程组解的个数 求出答案就是\(2^{自由元-1}\) , ...

  7. CodeForces:#448 div2 B. XK Segments

    传送门:http://codeforces.com/contest/895/problem/B B. XK Segments time limit per test1 second memory li ...

  8. CodeForces:#448 div2 a Pizza Separation

    传送门:http://codeforces.com/contest/895/problem/A A. Pizza Separation time limit per test1 second memo ...

  9. Codeforces Round #448(Div.2) Editorial ABC

    被B的0的情况从头卡到尾.导致没看C,心情炸裂又掉分了. A. Pizza Separation time limit per test 1 second memory limit per test ...

随机推荐

  1. WinSock网络编程基础(1)

    记录学习windows网络编程过程中遇到的问题和相关笔记 基本概念: Socket: socket起源于UNIX,Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口.基于&qu ...

  2. HDU 5584 LCM Walk(数学题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5584 题意:(x, y)经过一次操作可以变成(x+z, y)或(x, y+z)现在给你个点(ex, e ...

  3. BZOJ 3231: [Sdoi2008]递归数列( 矩阵快速幂 )

    矩阵乘法裸题..差分一下然后用矩阵乘法+快速幂就可以了. ----------------------------------------------------------------------- ...

  4. SQL 处理空值

    问题: 在数据库中经常会有为null和''的值的列,在查询的时候,我们需要将它们转化成有效的值. 解决方案: 在emp表中的comm注释有的为null有的为'',在查询的时候 我们希望没有注释的显示为 ...

  5. Android中自己定义组件和它的属性

    好长时间没有更新博客了.本来想积累点有深度的东西发,但一直没有找到非常好的点.所以.写一些基础的东西.就当积累吧. Android开发中难免会用到自己定义的组件.以下以ImageButton为例来介绍 ...

  6. The Building Blocks-Components of EA part 1- Information and Strategy

    1. Zachman Framework Presented as matrix of Rows and Columns representing domain of interest and lev ...

  7. superMap Object 属性查看的一点代码

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  8. API和DLL

    API API(Application Programming Interface,应用编程接口)其实就是操作系统留给应用程序的一个调用接口,应用程序通过调用操作系统的 API 而使操作系统去执行应用 ...

  9. poj 3259Wormholes (spfa最短路径)

    #include<stdio.h> #include<string.h> #include<limits.h> #include<queue> usin ...

  10. (转)openURL的使用方法

    view plaincopy to clipboardprint? [[UIApplication sharedApplication] openURL:[NSURL URLWithString:ap ...