uva 10461 Difference
来源:互联网 发布:淘宝卖家寄寿衣怎么办 编辑:程序博客网 时间:2024/06/07 19:17
Problem I
Difference
Input: standard input
Output: standard output
Time Limit: 6 seconds
You are given a list of jobs with associated time to complete them. Also are given a list of job dependencies. Your job is to calculate the maximum possible difference among all possible completion time of a particular job. For this problem, job dependency is a bit simpler. When a job depends on several other jobs to be completed, finishing of all of them will allow it to execute. Furthermore, jobs cannot be executed in parallel and there will be no idle moment.
In the above example job-B cannot be started before A and D. So it can be started after 5 days and it must be started after 7 days. Here for job-B, the difference is 2 days.
Input
Input starts with a pair of integers v(1<=v<=500) and e(0<=e<=500) where v represents the number of jobs and e represents the number of dependencies in the dependency list. Following is a line with v integers each indicating the time in days to complete the jobs where the i'th integer denotes the completion time of the i'th job. The jobs are numbered by integers from 1 to v. Next e lines has the form "x y" which means that job x should be completed prior to job y(1 <= x, y <= v). Next line has an integer q which denotes the number of queries to answer which is followed by q integers x (1 <= x <= v). A line with v = e = 0 ends the input session. Every block will be followed by a blank line. There will be no impractical situation (Each job can be completed) in input.
Output
For each query in a block output the result according to the problem description in a separate line. A blank line is essential after every block of data. See the sample output.
Sample Input
4 44 3 2 12 12 43 1 3 421 2 4 44 3 2 12 12 43 1 3 423 40 0
Sample Output
Case #1:12Case #2:34
Author : Mohammad Sajjad Hossain
The Real Programmers' Contest-2虽然是一道水题,还是要写解题报告吐槽一下。题中明明说所有任务都是可以完成的,为什么会出现环的情况。害我dfs没加vis判断超时到死,简直了。。。再吐槽今天多校,比赛没过的2题,赛后立马A了,这真是状态呀。。。
#include<cstdio>#include<map>#include<queue>#include<cstring>#include<iostream>#include<cstring>#include<algorithm>#include<vector>#include<list>#include<set>#include<cmath>using namespace std;const int maxn = 500 + 5;const int INF = 1000000000;const double eps = 1e-6;typedef unsigned long long ULL;typedef pair<int, int> P;#define fi first#define se secondvector<int> G[maxn];int t[maxn];int can[maxn][maxn];int vis[maxn];void dfs(int source, int x){ can[source][x] = 1; vis[x] = 1; for(int i = 0;i < G[x].size();i++){ int to = G[x][i]; if(!vis[to]) dfs(source, to); }}int main(){ int n, m; int kase = 0; while(scanf("%d%d", &n, &m)){ kase++; if(n == 0 && m == 0) break; for(int i = 1;i <= n;i++) scanf("%d", &t[i]); memset(can, 0, sizeof can); for(int i = 1;i <= n;i++) G[i].clear(); while(m--){ int x, y; scanf("%d%d", &x, &y); G[y].push_back(x); } for(int i = 1;i <= n;i++){ memset(vis, 0, sizeof vis); dfs(i, i); } printf("Case #%d:\n", kase); int q; scanf("%d", &q); while(q--){ int x; scanf("%d", &x); int ans = 0; for(int i = 1;i <= n;i++){ if(i != x){ if(can[x][i]!=1 && can[i][x]!=1) ans += t[i]; } } printf("%d\n", ans); } puts(""); } return 0;}
- uva 10461 Difference
- DB-difference
- Difference Equation
- Date Difference
- adjacent difference
- Expected Difference
- Smallest Difference
- difference hash
- Smallest Difference
- Smallest Difference
- Smallest Difference
- Difference Row
- Symmetric Difference
- HDU5936-Difference
- Getting Difference
- difference gradient
- Symmetric Difference
- Difference between Java & C++
- Centos7.0的几个新特性
- ViewHolder模式超简洁写法
- sqlite3 表里插入系统时间(时间戳)
- hdu 1150
- Data Types in the Kernel <LDD3 学习笔记>
- uva 10461 Difference
- 为Hero穿衣服
- hdu 1498
- C/C++高精度计时器类
- hdu1698Just a Hook segment_tree
- hdu 2119
- poj 3041
- HDU 1908 Double Queue(set)
- JQuery时间格式化插件--扩展JQuery