Gym 100703I---Endeavor for perfection(尺取)
题目链接
http://codeforces.com/problemset/gymProblem/100703/I
Description
Statements
As a matter of fact, Dragon knows what Prince is interested in now. Prince uses to spend his rare off days learning different courses and trainings. But Dragon doubts whether he should tell Princess about it.
Prince decided that he needs some extra knowledge and skills. He chose n fields in which he wanted to gain knowledge and skills most of all. After this, he learned that m1, m2, ..., mn courses and trainings of each of fields exist.
Prince took a close look at descriptions of courses and trainings and drew a table, in which sij is a value by which ith skill is increased after studying jth course (j = 1, 2, ..., mi).
Prince believes that his basic knowledge and skills in all these fields are negligible, so they can be considered zero. He wants to evolve his knowledge and skills harmonically. In his opinion, he will reach the greatest harmony if he chooses one course for each field in such a way that difference between the highest and the lowest their increases would be as minimum as possible.
Your task is to find the courses which Prince should choose.
Input
The first line contains integer n (1 ≤ n ≤ 200) — the number of fields which Prince is interested in.
The second line contains n integers m1, m2, ..., mn (1 ≤ mj ≤ 1000, j = 1, 2, ..., n) — the number of courses for each of fields.
The next n lines contain values sij (1 ≤ sij ≤ 109) — knowledges and skills, which Prince would gain at the courses. The first of thesen lines contains values s11, s12, ..., s1m1, the second — values s21, s22, ..., s2m2, etc.
The values sij are listed in the numerical order of courses for each of the fields.
Output
In the first line print one integer — minimum difference between the highest and the lowest numbers of increase.
In the second line print n integers — numbers of courses which Prince should choose. List the numbers in the same order in which the fields are listed.
If there is more than one answer — choose any of them.
Sample Input
2
2 3
4 3
3 1 2
0
2 1
4
3 5 4 5
8 7 15
3 10 4 8 5
4 4 4 5
1 2 12 8 9
3
2 5 4 4 题意:输入一个n,然后输入n个数,表示接下来输入的n行每行的数的个数,求在每行中选择一个数使得这n个数的最大值与最小值的差最小,输出最小的差值和每行选择的数的列号; 思路:尺取,将n行的数放在一起从小到大排序,定义s=0和e=0,表示s~e的一段区间,e向右移动,直到这个区间包含n行的数,那么node[e].x-node[s].x便是从这个区间选择的n行数的最小差值,然后s++,再让e右移,计算区间n行数最小差值...... 代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
using namespace std;
const int M=1e9+;
const int maxn=2e5+;
int A[],cnt[],vis[];
struct Node
{
int x,h,l;
}node[maxn],ans[];
bool cmp1(const Node s1,const Node s2)
{
return s1.x<s2.x;
}
bool cmp2(const Node s1,const Node s2)
{
return s1.h<s2.h;
} int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(cnt,,sizeof(cnt));
memset(vis,,sizeof(vis));
for(int i=;i<n;i++)
scanf("%d",&A[i]);
int tot=;
for(int i=;i<n;i++)
for(int j=;j<=A[i];j++)
{
scanf("%d",&node[tot].x);
node[tot].h=i;
node[tot++].l=j;
}
sort(node,node+tot,cmp1);
int tmp=M,s=,e=,sum=;
int pos1,pos2;
while()
{
while(e<tot&&sum<n){
cnt[node[e].h]++;
if(cnt[node[e].h]==) sum++;
e++;
}
if(sum<n) break;
if(node[e-].x-node[s].x<tmp){
tmp=node[e-].x-node[s].x;
pos1=s;
pos2=e-;
}
if(tmp==) break;
if(cnt[node[s].h]==) sum--;
cnt[node[s].h]--;
s++;
}
int p=;
for(int i=pos1;i<=pos2;i++)
{
if(vis[node[i].h]==)
{
vis[node[i].h]=;
ans[p].h=node[i].h;
ans[p++].l=node[i].l;
}
}
sort(ans,ans+n,cmp2);
printf("%d\n",tmp);
for(int i=;i<n;i++)
printf("%d%c",ans[i].l,(i+==n)?'\n':' ');
}
return ;
}
Gym 100703I---Endeavor for perfection(尺取)的更多相关文章
- CF GYM 100703I Endeavor for perfection
题意:有n个学习领域,每个领域有m个课程,学习第i个领域的第j个课程可以获得sij个技能点,在每个领域中选择一个课程,要求获得的n个技能点的最大值减最小值最小,输出符合要求的策略. 解法:尺取法.将课 ...
- Gym 101257G:24(尺取)
http://codeforces.com/gym/101257/problem/GGym 101257G 题意:给出n个人,和一个数s,接下来给出每个人当前的分数和输掉的概率.当一个人输了之后就会掉 ...
- NOJ 1072 The longest same color grid(尺取)
Problem 1072: The longest same color grid Time Limits: 1000 MS Memory Limits: 65536 KB 64-bit in ...
- hdu 4123 Bob’s Race 树的直径+rmq+尺取
Bob’s Race Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...
- poj2566尺取变形
Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...
- poj2100还是尺取
King George has recently decided that he would like to have a new design for the royal graveyard. Th ...
- hdu 6231 -- K-th Number(二分+尺取)
题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...
- Codeforces 939E Maximize! (三分 || 尺取)
<题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...
随机推荐
- Oracle 创建普通用户,并赋予权限
采用sys or system / manager as sysdba; 连接数据库. 创建普通用户konglin: create user konglin identified by pwd_ora ...
- WCF学习之旅—WCF第二个示例(六)
第五步,创建数据服务 在“解决方案资源管理器”中,使用鼠标左键选中“SCF.WcfService”项目,然后在菜单栏上,依次选择“项目”.“添加新项”. 在“添加新项”对话框中,选择“Web”节点,然 ...
- WPF自定义控件与样式(1)-矢量字体图标(iconfont)
一.图标字体 图标字体在网页开发上运用非常广泛,具体可以网络搜索了解,网页上的运用有很多例子,如Bootstrap.但在C/S程序中使用还不多,字体图标其实就是把矢量图形打包到字体文件里,就像使用一般 ...
- Android 设置对话框全屏
1.在styles.xml中添加一个style: <style name="Dialog_Fullscreen"> <item name="androi ...
- Android,App 常用图标尺寸规范
程序启动图标(Logo): 小屏ldpi() 36 x 36 px. 中屏mdpi(160dpi):48*48px 大屏hdpi(240dpi):72*72px 特大屏xhdpi(320dpi):96 ...
- Android NDK开发Hello Word!
在之前的博客中已经为大家介绍了,如何在win环境下配置DNK程序,本篇我将带大家实现一个简单的Hello jni程序,让大家真正感受一下NDK开发的魅力.这里我们选择使用C+JAVA开发Android ...
- EntityFramework 实体拆分和表拆分
之前有人问过 EF 如何进行实体拆分和表拆分?我记得当时认为不可能,理由忘记了,后来又有人发了一段配置截图,发现原来是可以的,不记录的东西容易忘掉,关于 EF 实体拆分和表拆分,下面是自己的一些整理. ...
- selenium操作隐藏的元素
有时候我们会碰到一些元素不可见,这个时候selenium就无法对这些元素进行操作了.例如,下面的情况: Python 页面主要通过“display:none”来控制整个下拉框不可见.这个时候如果直接操 ...
- APP接口自动化测试JAVA+TestNG(一)之框架环境搭建
前言 好久不曾写点啥,去年换到新公司组测试团队与培养建设花费大量时间与精力,终于架构成型与稳定有时间可以打打酱油了.很久没有总结点啥,提笔想写的内容太多,先放APP接口自动化的内容吧,这个估计大家比较 ...
- vue-lazy-render: 延迟渲染大组件,增强页面切换流畅度
最近用element来做项目,在开发的过程中,突然发现页面的操作和切换在数据量大的时候相当卡,后来提了个issue,在furybean解答后才知道,我每个单元格都加了tooltip,会生成大量的节点, ...