杭电 HDU 1031 Design T-Shirt
Design T-Shirt
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6527 Accepted Submission(s): 3061
satisfied. So he took a poll to collect people's opinions. Here are what he obtained: N people voted for M design elements (such as the ACM-ICPC logo, big names in computer science, well-known graphs, etc.). Everyone assigned each element a number of satisfaction.
However, XKA can only put K (<=M) elements into his design. He needs you to pick for him the K elements such that the total number of satisfaction is maximized.
into his design. Then N lines follow, each contains M numbers. The j-th number in the i-th line represents the i-th person's satisfaction on the j-th element.
one with minimal indices. The indices start from 1 and must be printed in non-increasing order. There must be exactly one space between two adjacent indices, and no extra space at the end of the line.
3 6 4
2 2.5 5 1 3 4
5 1 3.5 2 2 2
1 1 1 1 1 10
3 3 2
1 2 3
2 3 1
3 1 2
6 5 3 1
2 1
#include<iostream>
#include<algorithm>
#include<string.h>
const int M=100;
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
double ls[M][M];
double gq[M];
int flag[M];
int n,m,k,i,j,T;
while(scanf("%d%d%d",&n,&m,&k))
{
int x=0;
memset(gq,0,sizeof(gq));
memset(ls,0,sizeof(ls));
memset(flag,0,sizeof(flag));
for( i=0;i<n;i++)
for(j=0;j<m;j++)
{
scanf("%lf",&ls[i][j]);
gq[j]+=ls[i][j];
}
while(k--)
{
int max=-1;
for(int t=0;t<m;t++)
{
if(gq[t]>max)
{
max=gq[t];
T =t;
}
}
gq[T]=-1;
flag[x++]=T+1;
}
sort(flag,flag+x,cmp); for(int p=0;p<x-1;p++)
printf("%d ",flag[p]);
printf("%d\n",flag[x-1]);
}
return 0;
}
第二:
#include<iostream>
#include<algorithm>
#include<string.h> const int M=10000;
using namespace std; int main()
{
double ls[M][M];
double gq[M];
int flag[M];
int n,m,k,i,j,T;
while(scanf("%d%d%d",&n,&m,&k))
{
int x=0,I=k;
memset(gq,0,sizeof(gq));
memset(ls,0,sizeof(ls));
memset(flag,0,sizeof(flag));
for( i=0;i<n;i++)
for(j=0;j<m;j++)
{
scanf("%lf",&ls[i][j]);
gq[j]+=ls[i][j];
}
while(k--)
{
int max=-1;
for(int t=0;t<m;t++)
{
if(gq[t]>max)
{
max=gq[t];
T =t;
}
}
gq[T]=-1;
flag[T]=1;
} for(int p=m-1;p>=0;p--) {
if(flag[p]==1)
{
x++; if(x==I)
{
printf("%d\n",p+1); break;
} else printf("%d ",p+1);
}
}
}
return 0;
}
第三:AC代码:
#include<cmath>
#include<iostream>
using namespace std;
#include<algorithm>
#include<string.h>
const int N=10005;
struct ls
{
int k;
double sum;
}gq[N]; bool cmp1(ls a,ls b)
{ return a.sum>b.sum; }
bool cmp2(ls a,ls b)
{
return a.k>b.k;
} int main()
{
int n,m,k,i;
double re;
while(~scanf("%d%d%d",&n,&m,&k))
{
for(i=0;i<m;i++)
{
gq[i].k=i;
gq[i].sum=0.0;
}
for(int j=0;j<n;j++)
for(int t=0;t<m;t++)
{
scanf("%lf",&re);
gq[t].sum+=re; } sort(gq,gq+m,cmp1);
sort(gq,gq+k,cmp2);
for(int w=0;w<k-1;w++)
printf("%d ",gq[w].k+1);
printf("%d\n",gq[k-1].k+1);
}
return 0;
}
杭电 HDU 1031 Design T-Shirt的更多相关文章
- 杭电 HDU ACM 2795 Billboard(线段树伪装版)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 1031 Design T-Shirt
http://acm.hdu.edu.cn/showproblem.php?pid=1031 题意 :n个人,每个人对m件衣服打分,每个人对第 i 件衣服的打分要加起来,选取和前 k 高的输出他们的编 ...
- 杭电 HDU 4608 I-number
http://acm.hdu.edu.cn/showproblem.php?pid=4608 听说这个题是比赛的签到题......无语..... 问题:给你一个数x,求比它大的数y. y的要求: 1. ...
- 深搜基础题目 杭电 HDU 1241
HDU 1241 是深搜算法的入门题目,递归实现. 原题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1241 代码仅供参考,c++实现: #incl ...
- 杭电 HDU 1242 Rescue
http://acm.hdu.edu.cn/showproblem.php?pid=1242 问题:牢房里有墙(#),警卫(x)和道路( . ),天使被关在牢房里位置为a,你的位置在r处,杀死一个警卫 ...
- HDU 1031.Design T-Shirt【结构体二次排序】【8月21】
Design T-Shirt Problem Description Soon after he decided to design a T-shirt for our Algorithm Board ...
- ACM 杭电HDU 2084 数塔 [解题报告]
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- 杭电 HDU ACM 1698 Just a Hook(线段树 区间更新 延迟标记)
欢迎"热爱编程"的高考少年--报考杭州电子科技大学计算机学院 Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memor ...
- 杭电 HDU ACM Milk
Milk Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
随机推荐
- CodeForces 909E Coprocessor
题解. 贪心,拓扑排序. 和拓扑排序一样,先把$flag$为$0$的点能删的都删光,露出来的肯定都是$flag$为$0$的,然后疯狂删$flag$为$0$的,这些会使答案加$1$,反复操作就可以了. ...
- Process Explorer常用操作介绍
(未获得作者本人同意,严禁转载) Process Explorer出现的背景 Process Explorer可以看成是一个加强版的任务管理器.在较早的Windows版本中,任务管理器提供的功能是非常 ...
- RxJava 机制
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha rxjava 是 以 响应式 编程思想 编程的 java类库
- Java并发(十四):并发工具类——CountDownLatch
先做总结: 1.CountDownLatch 是什么? CountDownLatch 允许一个或多个线程等待其他线程(不一定是线程,某个操作)完成之后再执行. CountDownLatch的构造函数接 ...
- [转]Jquery实现页面定时跳转
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- CDOJ 1314 Hash Perfectly FFT
Hash Perfectly 题目连接: http://acm.uestc.edu.cn/#/problem/show/1314 Description In computing, a hash ta ...
- JProfiler 5.1.4的使用方法
1. JProfiler运行环境配置 安装目录结构如下,子目录中显示了支持的操作系统: 在服务器和客户端都要安装JProfiler,并且要安装License,在分析工具客户端中进行安装.Windows ...
- HDU 4493 Tutor (水题)
Tutor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submi ...
- Use two picogate devices for bidirectional level-shifting
In new mixed-voltage systems, it is often necessary to level-shift a control signal from a high leve ...
- Spring依赖检查
在Spring中,可以使用依赖检查功能,以确保所要求的属性可设置或者注入. 依赖检查模式 4个依赖检查支持的模式: none – 没有依赖检查,这是默认的模式. simple – 如果基本类型(int ...