杭电 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 ...
随机推荐
- HDU 6025 Coprime Sequence
枚举,预处理. 预处理前缀$gcd$与后缀$gcd$,枚举删哪一个即可. #include <bits/stdc++.h> using namespace std; int T,n; ]; ...
- 如果修改GeneXus Android的一些源码文件(FlexibleClient)
在使用GeneXus开发Android应用的过程中遇到了一个问题,使用tabs控件时发现默认高度过高,和UI设计要求的高度不一致,找了很久发现没有地方设置.后来联系了GeneXus中国厂商,得到了答复 ...
- http1.0和1.1的区别
1.HTTP 1.1支持长连接(PersistentConnection)和请求的流水线(Pipelining)处理 HTTP 1.0规定浏览器与服务器只保持短暂的连接,浏览器的每次请求都需要与服务器 ...
- Hibernate.cfg.xml详解
在搭建Hibernate环境时需要配置Hibernate.cfg.xml配置文件,本文将想详细讲解配置文件的内容. 1.数据库连接信息 配置数据库驱动.(其中name为连接方式,我在这写jdbc的连接 ...
- 【BZOJ 3144】 3144: [Hnoi2013]切糕 (最小割模型)
3144: [Hnoi2013]切糕 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1764 Solved: 965 Description Inp ...
- centos 7 修改ssh登录端口
在阿里云上面使用的oneinstack镜像,默认是使用的22端口,每次登录总会发现有人在暴力破解我的服务器,所以想想还是修改一下比较安全. 1.在防火墙打开新的端口 iptables -I INPUT ...
- HP-unix如何生成动态库?
HP-unix系统生成动态库编译的方法? 创建PIC中间文件的编译器选项是+z,创建动态库的链接器标志是-b. 1. cc +z d1.c d2.c /* 编译以".o"为扩展名的 ...
- C++虚函数、虚继承
http://blog.csdn.net/hackbuteer1/article/details/7883531 转载请标明出处,原文地址:http://blog.csdn.net/hackbutee ...
- mssql Row_Number() 分页 DISTINCT 问题
转载原文地址http://www.cnblogs.com/pumaboyd/archive/2008/04/20/1162376.html 这周碰到了很多奇怪的问题,有些是莫名的低级错误,有些这是一直 ...
- Django Pagination
Django provides a few classes that help you manage paginated data – that is, data that’s split acros ...