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个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- git 使用过程(二、创建版本库)
1.显示当前git所在操作文件路径 命令:pwd 2.改变当前操作路径 命令:cd /e/神马神马的,如果想到当前文件夹的某个子目录下,可以直接输入命令:cd 子目录名称,这样就可以了. 3.创建一 ...
- PHP - 直接输出对象的版本问题
- 【Oracle】SQL*Loader-522: lfiopn failed for file
Linux下使用sqlldr进行批量操作,此操作会自动生成和删除临时文件. 因此,当前操作的用户必须具备对存放文件的文件夹有增删改的权限. 使用root登录,修改改文件夹权限为777即可. chmod ...
- 断开/删除 SVN 链接(.svn)的几种方法
上传到正式的服务器时需要去掉这些不必要的文件,找到了几种方法: 1.windows下: xcopy project_dir project_dir_1 /s /i (从project_dir 复制文件 ...
- 基于Sql Server 2008的分布式数据库的实践(一)
原文 基于Sql Server 2008的分布式数据库的实践(一) 配置Sql Server 2008(Win7) 1.打开SQL server2012,使用windows身份登录 2.登录后,右键选 ...
- Elven Postman(二叉树)
Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- Spark Core源代码分析: Spark任务模型
概述 一个Spark的Job分为多个stage,最后一个stage会包含一个或多个ResultTask,前面的stages会包含一个或多个ShuffleMapTasks. ResultTask运行并将 ...
- LeetCode——TwoSum
题目: Given an array of integers, find two numbers such that they add up to a specific target number. ...
- POJ1700(过河问题)
#include<iostream> #include<algorithm> using namespace std; ]; int main() { int t,i; cin ...
- 对背包问题(Knapsack Problem)的算法探究
对背包问题(Knapsack Problem)的算法探究 至繁归于至简,这次自己仍然用尽可能易理解和阅读的解决方式. 1.问题说明: 假设有一个背包的负重最多可达8公斤,而希望在背包中装入负重范围内可 ...