qsort直接排序。

 #include <stdio.h>
#include <string.h>
#include <stdlib.h> #define MAXNUM 1000 typedef struct {
int index;
double statis;
} node_st; node_st nodes[MAXNUM]; int comp1(const void *a, const void *b) {
node_st *p = (node_st *)a;
node_st *q = (node_st *)b; if (p->statis == q->statis)
return p->index - q->index;
else
return (q->statis>p->statis) ? :-;
} int comp2(const void *a, const void *b) {
node_st *p = (node_st *)a;
node_st *q = (node_st *)b; return q->index - p->index;
} void output(int m) {
int i;
for (i=; i<=m; ++i)
printf("index=%d, statis:%lf\n", nodes[i].index, nodes[i].statis);
} int main() {
int n, m, k;
int i;
double tmp; while (scanf("%d %d %d", &n, &m, &k) != EOF) {
memset(nodes, , sizeof(nodes));
while (n--) {
for (i=; i<=m; ++i) {
scanf("%lf", &tmp);
nodes[i].statis += tmp;
}
}
for (i=; i<=m; ++i)
nodes[i].index = i;
qsort(nodes+, m, sizeof(node_st), comp1);
//output(m);
qsort(nodes+, k, sizeof(node_st), comp2);
//output(k);
for (i=; i<=k; ++i) {
if (i == )
printf("%d", nodes[i].index);
else
printf(" %d", nodes[i].index);;
}
printf("\n");
} return ;
}

01背包也可解。

 #include <stdio.h>
#include <string.h> #define MAXNUM 1000 double dp[MAXNUM];
double statis[MAXNUM];
char visit[MAXNUM][MAXNUM]; double max(double a, double b) {
return a>b ? a:b;
} int main() {
int n, m, k;
int i, j, p;
double tmp; while (scanf("%d%d%d",&n,&m,&k) != EOF) {
memset(dp, , sizeof(dp));
memset(statis, , sizeof(statis));
memset(visit, , sizeof(visit)); while (n--) {
for (i=; i<=m; ++i) {
scanf("%lf", &tmp);
statis[i] += tmp;
}
} for (i=; i<=m; ++i) {
for (j=k; j>; --j) {
tmp = dp[j-] + statis[i];
if (dp[j] < tmp) {
dp[j] = tmp;
for (p=; p<i; ++p)
visit[j][p] = visit[j-][p];
visit[j][i] = ;
}
}
}
i = ;
for (p=m; p>; --p) {
if (visit[k][p]) {
if (i)
printf(" %d", p);
else
printf("%d", p);
++i;
}
}
printf("\n");
} return ;
}

【HDOJ】1031 Design T-Shirt的更多相关文章

  1. 【转】【翻】Android Design Support Library 的 代码实验——几行代码,让你的 APP 变得花俏

    转自:http://mrfufufu.github.io/android/2015/07/01/Codelab_Android_Design_Support_Library.html [翻]Andro ...

  2. 【BZOJ】1031 [JSOI2007]字符加密Cipher

    [算法]后缀数组 [题解]把数组复制一遍然后SA处理即可. 后缀数组 #include<cstdio> #include<algorithm> #include<cstr ...

  3. 【HDOJ】P1007 Quoit Design (最近点对)

    题目意思很简单,意思就是求一个图上最近点对. 具体思想就是二分法,这里就不做介绍,相信大家都会明白的,在这里我说明一下如何进行拼合. 具体证明一下为什么只需要检查6个点 首先,假设当前左侧和右侧的最小 ...

  4. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  5. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  6. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  7. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  8. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

  9. 【HDOJ】【3415】Max Sum of Max-K-sub-sequence

    DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...

随机推荐

  1. C#微信公众号开发 -- (六)自定义菜单事件之CLICK

    微信公众号中当用户手动点击了按钮,微信公众号会被动的向用户发送文字消息或者图文消息. 通过C#微信公众号开发 -- (五)自定义菜单创建 我们知道了如何将CLICK类型的按钮添加到自己的微信公众平台上 ...

  2. ASP.NET MVC5总结(三)登陆中常用技术解析之session与cookie

    1.session机制 session机制是在服务器端保持状态的方案,在做系统登陆时,我们往往会用到session来存储一些用户登录的重要信息,而这些信息是不能存在cookie中的. 当访问量增多时, ...

  3. Deep Learning 学习随记(三)续 Softmax regression练习

    上一篇讲的Softmax regression,当时时间不够,没把练习做完.这几天学车有点累,又特别想动动手自己写写matlab代码 所以等到了现在,这篇文章就当做上一篇的续吧. 回顾: 上一篇最后给 ...

  4. iOS 多张图片保存到相册问题(add multiple images to photo album)

    不知道朋友们有木有做过多图保存到系统的相册这个需求,我在用`UIImageWriteToSavedPhotosAlbum`保存图片时候,在代理回调方`didFinishSavingWithError` ...

  5. 关于c++的输入

    vector<int> iv1, iv2; cout << "请为第一个vector容器装填整数元素,以s结尾:" << endl; int n ...

  6. groovy --不注意的小错误(java.lang.String.positive() is applicable)

    sql 语句拼接报错: No signature of method: java.lang.String.positive() is applicable for argument types: () ...

  7. ASP.NET缓存 Cache

    缓存介绍 如果每次进入页面的时候都查询数据库生成页面内容的话,如果访问量非常大,则网站性能会非常差,而如果只有第一次访问的时候才查询数据库生成页面内容,以后都直接输出内容,则能提高系统性能,这样无论多 ...

  8. go build 时报错 cc1.exe: sorry, unimplemented: 64-bit mode not compiled in

    最近在玩Go win下尝试编译Go的时候遇到了下面提示(可能是gorocksdb用到了gcc) gcc也需要64位的 最后找到了个帖子: https://github.com/mattn/go-sql ...

  9. As3 里的正则相关

    用正则的时候 不要用if(content.match("test").length > 0) ...; 改成 if(content.match(/test/g).length ...

  10. php 商务网站购物车联动地址

    数据表如下: CREATE TABLE IF NOT EXISTS `china` (`region_id` smallint(5) unsigned NOT NULL,  `parent_id` s ...