2017 ICPCECIC 北方邀请赛 H MJF wants to work (贪心)
MJF wants to work
时间限制: 1 Sec 内存限制: 128 MB
提交: 87 解决: 16
[提交][状态][讨论版]
题目描述
There are n jobs MJF can take part in.For job i, it has the start time ti.x, the end time ti.y and reward ci.
MJF wants to take part in two jobs (exact two jobs), and he wants to earn exactly M yuan. He doesn't want to earn one money more,he thinks it's a waste.
Becase MJF is a lazy boy, so he wants the time of the sum of two jobs shortest.
Becase MJF can only take part in one job in a time.So two jobs can't overlap.(ti.y < tj.x)
输入
For each test,the first line contains 2 integers n, m.(1 <= n, m <= 2e5)
Then following n lines, each line contains 3 integers ti.x, ti.y, ci.(1 <= ti.x, ti.y, ci <= 2e5)
输出
样例输入
3 10
1 2 3
3 4 7
4 6 7
1 10
1 10 10
样例输出
4
oh no!
123
思路为:
把 时间段 从线段 化成 左右两个端点 问题, 每个端点存 时间, 金钱 和 区分左右标志,
然后按照 左端点从小到大排序, 并且是 一左一右 排序, 遇到左端点, 维护ans 值, dp数组存的是 时间, 维护 m- 当前已挣得钱的 时间 尽可能小
遇到右端点 维护 dp 时间
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x) lower_bound(b+1,b+1+bn,x)-b
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w",stdout)
#define S1(n) scanf("%d",&n)
#define SL1(n) scanf("%I64d",&n)
#define S2(n,m) scanf("%d%d",&n,&m)
#define SL2(n,m) scanf("%I64d%I64d",&n,&m)
#define Pr(n) printf("%d\n",n)
using namespace std;
typedef long long ll;
const double PI=acos(-1);
const int INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};int n,m;
int cont;
int dp[maxn*2];// dp数组存的是时间
struct node{int x;int time;int mo;int flag;//0 左端点, 1 右端点
}a[maxn*2];
int cmp(node a,node b)
{if(a.x==b.x)return a.flag<b.flag;return a.x<b.x;}
void init()
{for(int i=0;i<=maxn;i++)dp[i]=INF;int x,y,z;mem(a,0);cont=0;for(int i=1;i<=n;i++){scanf("%d %d %d",&x,&y,&z);a[++cont].x=x;a[cont].time=y-x+1;a[cont].flag=0;a[cont].mo=z;a[++cont].x=y;a[cont].time=y-x+1;a[cont].flag=1;a[cont].mo=z;}sort(a+1,a+cont+1,cmp);int ans=INF;for(int i=1;i<=cont;i++){if(a[i].flag==0)ans=min(ans,dp[m-a[i].mo]+a[i].time);elsedp[a[i].mo]=min(dp[a[i].mo],a[i].time);}if(ans!=INF)printf("%d\n",ans);elseprintf("oh no!\n");}
int main()
{while(~scanf("%d %d",&n,&m)){init();}return 0;
}
Coach's plan
时间限制: 2 Sec 内存限制: 128 MB
提交: 57 解决: 15
[提交][状态][讨论版]
题目描述
Now our coach needs to draw up a plan, which satisfies:
1. every student uses one computer, and a computer can be used by no more than one student;
2. maximize the minimum suitability, which means if the answer is w, then everyone's suitability to his computer shouldn't be less than w.
Hint: huge input, please use fast IO.
输入
Next n lines describes every student's suitability to every computer, number in ith line and jth row means student[i]'s suitability to computer[j].
输出
样例输入
1 2
1 10
2 3
10 1 2
2 1 1
样例输出
10
2
找 列最小 水过的, 隔壁 找行最小 水过的, 然后 重判后 game over 隔隔壁, 找行列 最小 依然坚挺 ; mmp
水过代码: 找 行小列小, min 最小的,
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;int n,m,a[505][505],b[505],c[505];bool cmp(int x, int y){return x > y;
}int main(){while(~scanf("%d%d",&n,&m)){for(int i = 0; i < n; i ++){for(int j = 0; j < m; j ++)scanf("%d",&a[i][j]);}for(int i = 0; i < n; i ++){int mxx = a[i][0];for(int j = 1; j < m; j ++)mxx = max(a[i][j],mxx);b[i] = mxx;}for(int j = 0; j < m; j ++){int mxx = a[0][j];for(int i = 1; i < n; i ++)mxx = max(a[i][j],mxx);c[j] = mxx;}sort(b,b+n,cmp);sort(c,c+m,cmp);printf("%d\n",min(c[n-1],b[n-1]));}return 0;
}
正解是: 二分图匹配 + 二分查找;
把网格 从 一维 变成 二维 匹配 问题, 用到匈牙利算法,
比赛时, 考虑到 二分图匹配, 没 想到 要用到二分查找,
要用 链式前向星 存储 边l
1w 小心 , 一不小心 就超时;
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x) lower_bound(b+1,b+1+bn,x)-b
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w",stdout)
#define S1(n) scanf("%d",&n)
#define SL1(n) scanf("%I64d",&n)
#define S2(n,m) scanf("%d%d",&n,&m)
#define SL2(n,m) scanf("%I64d%I64d",&n,&m)
#define Pr(n) printf("%d\n",n)
using namespace std;
typedef long long ll;
const double PI=acos(-1);
const int INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};int n,m;
int maps[505][505];
struct Edge{int v,u;
}a[maxn];
int edge_cont;
int head[10005];
int match[10005];
bool used[10005];
void add(int u,int v)
{a[++edge_cont].v=v;a[edge_cont].u=head[u];head[u]=edge_cont;
}
int finds(int x)
{used[x]=1;for(int i=head[x];i!=-1;i=a[i].u)// 链式前向星 访问{int v=a[i].v;int w=match[v];if(w<0||!used[w]&&finds(w))// v 还没匹配 或者 能够找到更合适的{match[x]=v;match[v]=x;return 1;}}return 0;
}
int binary_match()//二分匹配
{int ans=0;mem(match,-1);for(int i=0;i<n;i++){if(match[i]<0)//未匹配{mem(used,0);if(finds(i))//可以找到合适的ans++;}}return ans;
}
bool judge(int x)
{edge_cont=0;mem(head,-1);for(int i=0;i<n;i++){for(int j=0;j<m;j++){if(maps[i][j]>=x){add(i,j+n); //无向图add(j+n,i);}}}if(binary_match()==n)return true;return false;
}
void work()
{int ans;int l=0;int r=1001;while(r-l>1){int mid=(l+r)>>1;if(judge(mid))l=mid;elser=mid;}cout<<l<<endl;
}
int main()
{while(~scanf("%d %d",&n,&m)){mem(maps,0);mem(a,0);min_num=INF;max_num=0;for(int i=0;i<n;i++)for(int j=0;j<m;j++){scanf("%d",&maps[i][j]);}work();}return 0;
}
123
2017 ICPCECIC 北方邀请赛 H MJF wants to work (贪心)相关推荐
- 2020 年 “联想杯”全国高校程序设计在线邀请赛H. Hay Mower
2020 年 "联想杯"全国高校程序设计在线邀请赛H. Hay Mower 题意:n × m 网格图,每个格子内的草每秒增加 ai,j,接下 来 k 个操作,每个操作会在某个时间把 ...
- 2017湘潭大学邀请赛H题(树的直径)
链接:https://www.icpc.camp/contests/4mYguiUR8k0GKE H. Highway The input contains zero or more test cas ...
- 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛:H—Highway
题目链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1267 Highway In ICPCCamp there wer ...
- 2017大学生程序设计邀请赛(华东师范大学) A.拼音魔法
传送门:http://acm.ecnu.edu.cn/problem/3256/ 魔法学校小学一年级有一种题.就是给一个字的拼音,给一个声调,让你正确地注音.但魔法老师给了巨量的题,你不用魔法根本不可 ...
- ACM-ICPC北京赛区2017网络同步赛H
http://hihocoder.com/contest/icpcbeijing2017/problem/8 预处理暴力枚举修改的点 #include <bits/stdc++.h> us ...
- 【错误】Visual Studio 2017 版本生成pch.h,什么是pch.h?
每次创建完vs项目都会出现这么一个文件,要是新建一个源文件没include这个pch.h ,还会报错: 这个东西究竟有什么用呢? 解释: pch 代表 precompiled header,预编译头, ...
- 一类SG函数递推性质的深入分析——2018ACM陕西邀请赛H题
题目描述 定义一种有根二叉树\(T(n)\)如下: (1)\(T(1)\)是一条长度为\(p\)的链: (2)\(T(2)\)是一条长度为\(q\)的链: (3)\(T(i)\)是一棵二叉树,它的左子 ...
- 2017.5.28 codeforce h题思考记录
并没有报codeforce 但有人想让我帮他看题,于是就做了 大概意思就是,给你200个空,让你在200个空中放字母, 再自己设计一个串,要求自己设计的这个串在这放着200个字母的串中作为子串出 ...
- 【文献阅读】MUTAN——多模态塔克融合VQA模型(Hedi Ben-younes等人,ArXiv,2017,有代码)
一.背景 文章题目:<MUTAN: Multimodal Tucker Fusion for Visual Question Answering> 17年的一篇文章,不过后面看到很多文献引 ...
- Gym101522GHIJKL----La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017
La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017 文章目录 La Salle-Pui Ching Programming Challeng ...
最新文章
- win8计算机管理没有用户组,Win8右键计算机管理提示“该文件没有与之关联的程序”怎么办?...
- Spring AOP切点表达式详解
- css中width:100%与width:auto的区别
- 教你用java统计目录下所有文档的词频
- CVPR 2018 论文解读 | 基于GAN和CNN的图像盲去噪
- 配置php7.2.4支持swoole2.1.1扩展
- Linux iostat和vmstat命令
- CoreAnimation-CATransform3D-1
- OpenStack-Pike(二)
- c语言文本编辑器源代码_程序员专属的10个免费编程文本编辑器,哪个是你的最爱?...
- C语言字符串函数(strcpy,strlen,strcat,stsstr,strchr,strcmp,memcpy,memmove)
- axure如何实现跳转_Axure 9 教程:如何做跑马灯广告、弹幕
- 物联网可靠连接——PLC-IOT电力线载波通讯
- aso优化师是什么_来肯云商app官网下载_做ASO优化师,只懂刷榜就够了吗
- 平均值、中位数、众数、极差分别是什么?各有什么有点和缺点?
- kakfa 3.0 创建topic流程(源码)
- 微信公众号开发之网页授权获取用户基本信息
- java使用ajax请求下载excel响应结果显示乱码
- java qq邮箱登录_SpringBoot实现QQ邮箱注册和登录
- 图像视频伪造检测,针对DeepFake技术检测效果不佳