这就是个超级水题……!!!!写一写来纪念一下自己的错误……

如果某个学生的的成绩是其他俩个或三个学生成绩的和则给予奖励

直接暴力,所以一开始直接用数组标记两个人或三个人的和,但是忽略了这种情况 20(学生A) =  0 +20(学生A)……

错误代码……!!!

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <cstdlib>
  7.  
  8. const int MAXN = + ;
  9. const double ESP = 10e-;
  10. const double Pi = atan(1.0) * ;
  11. const int INF = 0xffffff;
  12. const int MOD = ;
  13.  
  14. using namespace std;
  15. struct People{
  16. int s;
  17. char n[];
  18. bool operator < (const People a)const{
  19. if(strcmp(n,a.n) < )
  20. return ;
  21. return ;
  22. }
  23. };
  24. People a[MAXN];
  25. bool vis[];
  26. int main(){
  27. // freopen("input.txt","r",stdin);
  28. int t;
  29. scanf("%d",&t);
  30. int n;
  31. while(t--){
  32. scanf("%d",&n);
  33. memset(vis,,sizeof(vis));
  34. for(int i = ;i < n;i++){
  35. getchar();
  36. scanf("%s %d",a[i].n,&a[i].s);
  37. }
  38. sort(a,a+n);
  39. for(int i = ;i < n;i++){
  40. for(int j = i+;j < n;j++){
  41. int tt = a[i].s + a[j].s;
  42. vis[tt] = ;
  43. for(int k = j+;k < n;k++){
  44. tt = a[i].s + a[j].s + a[k].s;
  45. vis[tt] = ;
  46. }
  47. }
  48. }
  49. int cnt = ;
  50. for(int i = ;i < n;i++){
  51. if(vis[ a[i].s ]){
  52. cnt++;
  53. }
  54. }
  55. printf("%d\n",cnt);
  56. for(int i = ;i < n;i++){
  57. if(vis[ a[i].s ]){
  58. printf("%s\n",a[i].n);
  59. }
  60. }
  61.  
  62. }
  63. return ;
  64. }

正确……

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <string>
  8.  
  9. const int MAXN = + ;
  10. const double ESP = 10e-;
  11. const double Pi = atan(1.0) * ;
  12. const int INF = 0xffffff;
  13. const int MOD = ;
  14.  
  15. using namespace std;
  16. struct People{
  17. int s;
  18. string n;
  19. };
  20. People a[MAXN];
  21. string str[MAXN];
  22. int main(){
  23. //freopen("input.txt","r",stdin);
  24. int t;
  25. scanf("%d",&t);
  26. int n;
  27. while(t--){
  28. scanf("%d",&n);
  29. for(int i = ;i < n;i++){
  30. cin >> a[i].n >> a[i].s;
  31. }
  32. int cnt = ;
  33. for(int i = ;i < n;i++){
  34. for(int j = ;j < n;j++){
  35. if(i == j)
  36. continue;
  37. for(int k = ;k < n;k++){
  38. if(k == i || k == j)
  39. continue;
  40. if(a[i].s == a[j].s + a[k].s){
  41. str[cnt++] = a[i].n;
  42. k = n;
  43. j = n;
  44. break;
  45. }
  46. for(int l = ;l < n;l++){
  47. if(l == k || l == i || l == j){
  48. continue;
  49. }
  50. if(a[i].s == a[j].s+a[k].s+a[l].s){
  51. str[cnt++] = a[i].n;
  52. k = n;
  53. j = n;
  54. l = n;
  55. break;
  56. }
  57. }
  58. }
  59. }
  60. }
  61. cout << cnt << endl;
  62. sort(str,str+cnt);
  63. for(int i = ;i < cnt;i++){
  64. cout << str[i] << endl;
  65. }
  66. }
  67. return ;
  68. }

poj 3778的更多相关文章

  1. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  2. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  3. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  4. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  5. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  6. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  7. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  8. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

  9. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

随机推荐

  1. sc delete 服务名

    当我们在cmd里使用 sc delete  服务名  ,来删除服务的时候,报错误,SC OpenService 失败5:拒绝访问. 这似乎是因为权限不够,解决方法. 首先,我们必须先取得管理员权限,以 ...

  2. ios中利用NSDateComponents、NSDate、NSCalendar判断当前时间是否在一天的某个时间段内。

    应用中设置一般会存在这样的设置,如夜间勿扰模式,从8:00-23:00,此时如何判断当前时间是否在该时间段内.难点主要在于如何用NSDate生成一个8:00的时间和23:00的时间,然后用当前的时间跟 ...

  3. 【STL__set_的应用】

    1.关于set C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器, 更重要的是STL封装了许多复杂的数据结构算法和大量常用数据结 ...

  4. 字符串如何判断null.

    转http://blog.sina.com.cn/s/blog_48cd37140101awgq.html Java中判断String不为空的问题 一.判断一个字符串str不为空的方法有: 1. st ...

  5. 让Solr返回JSON数据

    http://localhost:1985/solr/select/?q=*%3A*&version=2.2&start=0&rows=10&indent=on& ...

  6. php language construct 语言构造器

    isset和empty看起来像是函数,我们也经常把它当作函数一样使用,但是实际上,它们是语言构造器. php中的语言构造器就相当于C中的预定义宏的意思,它属于php语言内部定义的关键词,不可以被修改, ...

  7. Flowers(二分水过。。。)

    Flowers Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  8. CSS - 解决使用浮动,父窗体不能撑高问题

    浮动的父级元素一定要用 clear 清除浮动,否则高度会无法撑开.

  9. windows phone 8的新特性

    <1>硬件的升级WP8在硬件上有了极大的提升,处理器支持双核或多核 理论最大支持64核,分辨率支持800x480.1280x720/768,屏幕支持720p或WXGA:支持存储卡扩展.同时 ...

  10. AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3參数含义

    arg0:是指父Vjew arg1就是你点击的那个Item的View arg2是position,position是你适配器里面的position arg3是id,通常是第几个项.id是哪个项View ...