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个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- sc delete 服务名
当我们在cmd里使用 sc delete 服务名 ,来删除服务的时候,报错误,SC OpenService 失败5:拒绝访问. 这似乎是因为权限不够,解决方法. 首先,我们必须先取得管理员权限,以 ...
- ios中利用NSDateComponents、NSDate、NSCalendar判断当前时间是否在一天的某个时间段内。
应用中设置一般会存在这样的设置,如夜间勿扰模式,从8:00-23:00,此时如何判断当前时间是否在该时间段内.难点主要在于如何用NSDate生成一个8:00的时间和23:00的时间,然后用当前的时间跟 ...
- 【STL__set_的应用】
1.关于set C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器, 更重要的是STL封装了许多复杂的数据结构算法和大量常用数据结 ...
- 字符串如何判断null.
转http://blog.sina.com.cn/s/blog_48cd37140101awgq.html Java中判断String不为空的问题 一.判断一个字符串str不为空的方法有: 1. st ...
- 让Solr返回JSON数据
http://localhost:1985/solr/select/?q=*%3A*&version=2.2&start=0&rows=10&indent=on& ...
- php language construct 语言构造器
isset和empty看起来像是函数,我们也经常把它当作函数一样使用,但是实际上,它们是语言构造器. php中的语言构造器就相当于C中的预定义宏的意思,它属于php语言内部定义的关键词,不可以被修改, ...
- Flowers(二分水过。。。)
Flowers Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- CSS - 解决使用浮动,父窗体不能撑高问题
浮动的父级元素一定要用 clear 清除浮动,否则高度会无法撑开.
- windows phone 8的新特性
<1>硬件的升级WP8在硬件上有了极大的提升,处理器支持双核或多核 理论最大支持64核,分辨率支持800x480.1280x720/768,屏幕支持720p或WXGA:支持存储卡扩展.同时 ...
- AdapterView<?> arg0, View arg1, int arg2, long arg3參数含义
arg0:是指父Vjew arg1就是你点击的那个Item的View arg2是position,position是你适配器里面的position arg3是id,通常是第几个项.id是哪个项View ...