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

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

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

错误代码……!!!

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib> const int MAXN = + ;
const double ESP = 10e-;
const double Pi = atan(1.0) * ;
const int INF = 0xffffff;
const int MOD = ; using namespace std;
struct People{
int s;
char n[];
bool operator < (const People a)const{
if(strcmp(n,a.n) < )
return ;
return ;
}
};
People a[MAXN];
bool vis[];
int main(){
// freopen("input.txt","r",stdin);
int t;
scanf("%d",&t);
int n;
while(t--){
scanf("%d",&n);
memset(vis,,sizeof(vis));
for(int i = ;i < n;i++){
getchar();
scanf("%s %d",a[i].n,&a[i].s);
}
sort(a,a+n);
for(int i = ;i < n;i++){
for(int j = i+;j < n;j++){
int tt = a[i].s + a[j].s;
vis[tt] = ;
for(int k = j+;k < n;k++){
tt = a[i].s + a[j].s + a[k].s;
vis[tt] = ;
}
}
}
int cnt = ;
for(int i = ;i < n;i++){
if(vis[ a[i].s ]){
cnt++;
}
}
printf("%d\n",cnt);
for(int i = ;i < n;i++){
if(vis[ a[i].s ]){
printf("%s\n",a[i].n);
}
} }
return ;
}

正确……

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <string> const int MAXN = + ;
const double ESP = 10e-;
const double Pi = atan(1.0) * ;
const int INF = 0xffffff;
const int MOD = ; using namespace std;
struct People{
int s;
string n;
};
People a[MAXN];
string str[MAXN];
int main(){
//freopen("input.txt","r",stdin);
int t;
scanf("%d",&t);
int n;
while(t--){
scanf("%d",&n);
for(int i = ;i < n;i++){
cin >> a[i].n >> a[i].s;
}
int cnt = ;
for(int i = ;i < n;i++){
for(int j = ;j < n;j++){
if(i == j)
continue;
for(int k = ;k < n;k++){
if(k == i || k == j)
continue;
if(a[i].s == a[j].s + a[k].s){
str[cnt++] = a[i].n;
k = n;
j = n;
break;
}
for(int l = ;l < n;l++){
if(l == k || l == i || l == j){
continue;
}
if(a[i].s == a[j].s+a[k].s+a[l].s){
str[cnt++] = a[i].n;
k = n;
j = n;
l = n;
break;
}
}
}
}
}
cout << cnt << endl;
sort(str,str+cnt);
for(int i = ;i < cnt;i++){
cout << str[i] << endl;
}
}
return ;
}

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. vim下设置tab

    前言:大多数情况下tab键的宽度设置为4个空格,这个可以根据自己 的代码风格进行替换,然而当你提交不同的语言的代码的时候python 和c的时候就有区别了.c的话一般tab键做缩进,而python提交 ...

  2. java多线程监听JMS、MQ队列

    本作品采用知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可. 转载请注明出处和作者.http://blog.csdn.net/xtj332 背景:消息队列中有非常多的消息需要 ...

  3. 《算法导论》读书笔记之图论算法—Dijkstra 算法求最短路径

    自从打ACM以来也算是用Dijkstra算法来求最短路径了好久,现在就写一篇博客来介绍一下这个算法吧 :) Dijkstra(迪杰斯特拉)算法是典型的最短路径路由算法,用于计算一个节点到其他所有节点的 ...

  4. POJ1273 最大流 EK算法

    套了个EK的模板 //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdi ...

  5. windows服务怎么向应用程序发消息(部署在同一台机,非SCOKET)

    命名管道:NamedPipeClientStream & NamedPipeClientStream 参考实例:http://msdn.microsoft.com/zh-cn/library/ ...

  6. KINGSO介绍

    kingso_intro - Taocode KINGSO介绍 KINGSO是一种高效的垂直化的搜索引擎,其包含query解析.检索.过滤.统计.排序功能,不包含抓取部分.它对商品搜索做了针对性的优化 ...

  7. Java字符串排序中文+数字

    编写日期: 2013年9月15日 另一中解法:点击查看 解决思路: 在Java中,排序需要复写的是 equals 方法 和 Comparable<T> 接口 的public int com ...

  8. vim-ctags-taglist-netrw

    vim配置 在~/.vimrc文件里配置例如以下内容.或者在/etc/vim/vimrc中进行全局配置,经常使用配置例如以下: syntax on set tabstop=4 set nu set s ...

  9. phantomjs环境搭建已经运行

    1.下载phantomjs http://phantomjs.org/ 2.运行 新建phantomjs.bat,记得改目录路径 里面内容为: D:\java\phantomjs\phantomjs. ...

  10. Android - Mac系统Android程序位置

    Mac系统Android程序位置 本文地址: http://blog.csdn.net/caroline_wendy Mac系统是类Unix系统.Android程序直接安装至目录.能够使用" ...