poj 3778
这就是个超级水题……!!!!写一写来纪念一下自己的错误……
如果某个学生的的成绩是其他俩个或三个学生成绩的和则给予奖励
直接暴力,所以一开始直接用数组标记两个人或三个人的和,但是忽略了这种情况 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的更多相关文章
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- 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 ...
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- HDU 1862 EXCEL次序 (排序水问题)
Problem Description Excel对能够记录一组由任意列排序指定.现在,请把你编译的代码类似特征. Input 測试输入包括若干測试用例. 每一个測试用例的第1行包括两个整数 N ...
- android动效开篇
大神博客:http://blog.csdn.net/tianjian4592/article/details/44155147 在现在的Android App开发中,动效越来越受到产品和设计师同学的重 ...
- hdu 5057 Argestes and Sequence
Argestes and Sequence Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- CUDA纹理绑定
纹理绑定的一般步骤: size_t fea_pitch; texture<unsigned char, 2> features2D; cudaMallocPitch((void**)(&a ...
- HDU 3925 Substring 【大数相减】
题目意思是,给你提供两个数字 a 和 b a 可以不断的往上加, 直到b 为其子串 问的是 a 最小加几? 显而易见,a 的数据范围给了10 ^100非常大,直接模拟肯定不行 那么就用 b 减去 a ...
- 转:MySql的commit和rollback
从功能上划分,SQL 语言可以分为DDL,DML和DCL三大类.1. DDL(Data Definition Language) 数据定义语言,用于定义和管理 SQL 数据库中的所有对象的语言 ...
- 15个最受欢迎的Python开源框架
以下是伯乐在线从GitHub中整理出的15个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python Web应用开发框 ...
- SQL SERVER 2008R2sp1配置Database Mail –用SQL 数据库发邮件
步骤1)创建配置文件和帐户 看图片吧,挺简单的: 中间略过的一些步骤,就点下一步即可. 下面我们测试一下: Step 2)配置邮件: 在完成账户和配置文件创建之后,我们需要配置Database Mai ...
- C# 课堂总结5-数组
一. 数组:解决同一类大量数据在内存存储和运算的功能. 1.一维数组定义:制定类型,指定长度,指定名称.int[] a=new int[5]int[] a=new int[5]{23,23,23,1, ...
- 四、Nginx负载均衡upstream
user www; worker_processes ; error_log /usr/local/nginx/logs/error.log crit; pid /usr/local/nginx/lo ...