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个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- iOS中正确的截屏姿势
昨天写了个用到截屏功能的插件,结果问题不断,今天终于解决好了,把debug过程中所有尝试过的截屏方法都贴出来吧- 第一种 这是iOS 3时代开始就被使用的方法,它被废止于iOS 7.iOS的私有方法, ...
- 【OpenMesh】使用网格的属性和特征
例子主要展示如何改变位置,法向量,颜色和纹理的数据类型. 在之前的指南中我们学习使用标准属性,通过调用适合的请求方法.不像自定义属性,用户通过传递数据类型到句柄来指定数据类型(比如,MyMesh::F ...
- php5.3升级到5.5
在网站中发布中: / 开启调试模式 建议开发阶段开启 部署阶段注释或者设为falsedefine('APP_DEBUG',true); true没问题,改为:false就报错 报错如下: PHP Fa ...
- 错误处理try catch
<?phpfunction inverse($x) { if (!$x) { throw new Exception('被除数不能为0'); } if ($x>31) { throw ne ...
- Chapter 9 原型模式
原型模式:用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. 简单的说就是clone一个对象实例.使得clone出来的copy和原有的对象一模一样. 插一个简单使用clone的例子,如果 ...
- Android studio多个项目之间怎么实现快速切换?
Android studio多个项目之间怎么实现快速切换?Android studio中打开的项目太多了,想切换到一个项目很麻烦,怎么才能快速切换到另一个项目中呢?请看下文详细介绍 在对Android ...
- Clojure学习03:数据结构(集合)
Clojure提供了几种强大的数据结构(集合) 一.集合种类 1.vector 相当于数组,如: [2 3 5] , ["ad" "adas" & ...
- [置顶] 深入ResourceBundle
ResourceBundle是java开发中非常实用的一个类,主要用来处理应用程序多语言这样的国际化问题. 如果你的应用程序如果有国际化的需求,可以考虑使用ResourceBundle, 你要做的就是 ...
- jQuery推断复选框是否勾选
今天要实现一功能就是:复选框勾选时给input表单赋值,复选框取消时将表单值清除. 效果如图: 实现源代码:cyfID为复选框的id $("#cyfID").click(funct ...
- SICP中sqrt(开方)的实现(附C#实现)
#lang racket (define (square x) (* x x)) (define (sqrt-iter guess x) (if (good-enough? guess x) gues ...