codeforces 589 G - Hiring(模拟?)
2015-10-27 21:10
411 查看
G - Hiring
Time Limit:4000MS Memory Limit:524288KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 589GDescriptionThe head of human resources department decided to hire a new employee. He created a test exercise for candidates which should be accomplished in at most m working days. Each candidate has to pass this test exercise. During the j-th day a candidate is allowed to be in the office for at most tj units of time.Overall, n candidates decided to apply for the job and sent out their resumes. Based on data received the head has defined two parameters describing every candidate: di and ri. The parameter di is the time to get prepared for work which the i-th candidate spends each morning. This time doesn't depend on day. The parameter ri is the total working time needed for the i-th candidate to accomplish the whole test exercise.Thus the time spent in the office in the j-th day consists of di units of time to get prepared and some units of time to proceed with the exercise. A candidate can skip entire working day and do not come to the office. Obviously in this case he doesn't spend di units of time to prepare.To complete the exercise a candidate should spend exactly ri units of time working on the exercise (time to prepare is not counted here).Find out for each candidate what is the earliest possible day when he can fully accomplish the test exercise. It is allowed to skip working days, but if candidate works during a day then he must spend di units of time to prepare for work before he starts progressing on the exercise.InputThe first line contains two integer numbers n, m(1 ≤ n, m ≤ 2·105) — the number of candidates and the maximum number of working days to do the test exercise.The second line contains m integer numbers t1, t2, ..., tm(1 ≤ tj ≤ 106) — the durations of working days in time units.The following n lines contain two integers each: di, ri(0 ≤ di ≤ 106, 1 ≤ ri ≤ 106) — how much time in the beginning of a day is required for i-th candidate before he starts his work on the test exercise and how much time it is needed for him to accomplish this task.OutputOutput a sequence of n integer numbers b1, b2, ..., bn, where bi is the earliest day when the i-th candidate can finish the test exercise.In case the i-th candidate cannot finish the test exercise in m days output bi = 0.Days in this problem are numbered from 1 to m in the order they are given in the input.Sample InputInput
Time Limit:4000MS Memory Limit:524288KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 589GDescriptionThe head of human resources department decided to hire a new employee. He created a test exercise for candidates which should be accomplished in at most m working days. Each candidate has to pass this test exercise. During the j-th day a candidate is allowed to be in the office for at most tj units of time.Overall, n candidates decided to apply for the job and sent out their resumes. Based on data received the head has defined two parameters describing every candidate: di and ri. The parameter di is the time to get prepared for work which the i-th candidate spends each morning. This time doesn't depend on day. The parameter ri is the total working time needed for the i-th candidate to accomplish the whole test exercise.Thus the time spent in the office in the j-th day consists of di units of time to get prepared and some units of time to proceed with the exercise. A candidate can skip entire working day and do not come to the office. Obviously in this case he doesn't spend di units of time to prepare.To complete the exercise a candidate should spend exactly ri units of time working on the exercise (time to prepare is not counted here).Find out for each candidate what is the earliest possible day when he can fully accomplish the test exercise. It is allowed to skip working days, but if candidate works during a day then he must spend di units of time to prepare for work before he starts progressing on the exercise.InputThe first line contains two integer numbers n, m(1 ≤ n, m ≤ 2·105) — the number of candidates and the maximum number of working days to do the test exercise.The second line contains m integer numbers t1, t2, ..., tm(1 ≤ tj ≤ 106) — the durations of working days in time units.The following n lines contain two integers each: di, ri(0 ≤ di ≤ 106, 1 ≤ ri ≤ 106) — how much time in the beginning of a day is required for i-th candidate before he starts his work on the test exercise and how much time it is needed for him to accomplish this task.OutputOutput a sequence of n integer numbers b1, b2, ..., bn, where bi is the earliest day when the i-th candidate can finish the test exercise.In case the i-th candidate cannot finish the test exercise in m days output bi = 0.Days in this problem are numbered from 1 to m in the order they are given in the input.Sample InputInput
3 3 4 2 5 1 3 2 5 3 4Output
1 3 0 需要注意。。。对于d相同的可以在之前的基础上直接处理。。。 不然可能tle..
/************************************************************************* > File Name: code/hust/20151025/H.cpp > Author: 111qqz > Email: rkz2013@126.com > Created Time: 2015年10月27日 星期二 19时30分28秒 ************************************************************************/ #include<iostream> #include<iomanip> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<string> #include<map> #include<set> #include<queue> #include<vector> #include<stack> #include<cctype> #define yn hez111qqz #define j1 cute111qqz #define ms(a,x) memset(a,x,sizeof(a)) #define pb push_back using namespace std; const int dx4[4]={1,0,0,-1}; const int dy4[4]={0,-1,1,0}; typedef long long LL; typedef double DB; const int inf = 0x3f3f3f3f; const int N=5E4+7; int n,m,k; vector<int> adj ; vector<pair< pair<int,int> ,int> > ans; int pa ; int kt ; bool spe ; void init() { ms(spe,false); ms(pa,0); scanf("%d %d %d",&n,&m,&k); for ( int i = 0,u,v; i < m ; i++) { scanf("%d %d",&u,&v); adj[u].push_back(v); adj[v].push_back(u); } for ( int i = 0,u ; i < k ; i++) { scanf("%d",&u); spe[u] = true; } } void dfs( int u) { // cout<<"u:"<<u<<endl; vector<int> tmp; tmp.clear(); for ( int j = 0 ; j < adj[u].size(); j++) { int v =adj[u][j]; if (pa[v]==0) { pa[v] = u; dfs(v); if (kt[v]) tmp.push_back(kt[v]); } } while (tmp.size()>1) { int x1 = tmp.back();tmp.pop_back(); int x2 = tmp.back(); tmp.pop_back(); // cout<<"x1:"<<x1<<" x2:"<<x2<<endl; ans.pb(make_pair(make_pair(x1,x2),u)); } if (tmp.size()>0) { int x = tmp.back();tmp.pop_back(); // cout<<"x:"<<x<<endl; if (spe[u]) { ans.push_back(make_pair(make_pair(x,u),u)); } else kt[u] = x; } else { if (spe[u]) kt[u] = u; } } void solve() { for ( int i = 1 ; i <n+1 ; i++) if (!pa[i]) { pa[i] = -1; dfs(i); } vector<int>p,q; // printf("%d\n",ans.size()); cout<<ans.size()<<endl; for ( int i = 0 ; i < ans.size(); i++) { int u = ans[i].first.first; int v = ans[i].first.second; int r = ans[i].second; // cout<<"************************"<<endl; // cout<<"u:"<<u<<" v:"<<v<<" r:"<<r<<endl; // cout<<"************************"<<endl<<endl; p.clear(); q.clear(); while (u!=r) { p.push_back(u); u = pa[u]; } while (v!=r) { q.push_back(v); v = pa[v]; } //printf("%d ",p.size()+q.size()); cout<<p.size()+q.size()<<" "; for ( int j = 0 ; j < p.size(); j++) printf("%d ",p[j]); printf("%d ",r); reverse(q.begin(),q.end()); for ( int j = 0 ; j < q.size(); j++) printf("%d ",q[j]); puts(""); } } int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif init(); solve(); #ifndef ONLINE_JUDGE fclose(stdin); #endif return 0; }View Code
相关文章推荐
- CheungSSH运维自动化软件 批量管理上千台服务器
- 1026作业
- 关于$_SESSION的一个坑
- [Leetcode]Reverse Linked List II
- 最基础的sql语句积累
- IMAGE_DOS_HEADER STRUCT小记
- 洛谷P1020/CODEVS1044 导弹拦截(拦截导弹)
- Android的http协议
- 多继承 虚继承
- 不可不知的android开发冷知识1
- 求职总结
- OC 复合问题 男人和女人问题
- Unity3D 第八章 实例化
- 异步任务
- C#字符串的不变性
- 什么是动态sql
- VIM命令大全
- opencv 将两张图片显示到一幅图片中
- 日经春秋 20151027
- IOS tabBarController 嵌套navigationController 实现多个界面的跳转