uva 11766 Racing Car Computer(DP)
来源:互联网 发布:givens矩阵变换 编辑:程序博客网 时间:2024/06/06 02:56
F
Racing Car Computer
Input: Standard Input
Output: Standard Output
The racing cars of today are equipped with so many sophisticated equipment. Introduction of a new visual transducer which is interfaced with the on-board computer can tell you on the fly how many cars are ahead of you while how many are trailing. There areN cars on a racing track. Each has an on-board computer with the new feature. During the race, every single car's computer keeps displaying two integers,a (The number of cars in front of him) & b (The number of cars behind him) for a particular moment. It is possible that at some time, some of the cars are racing side by side i.e. they are exactly at the same location. A car will not consider any other car at the same location to be a leading or trailing car.
Now, it is suspected that some of the new transducers are not working properly inside such high speed vehicles. The report with all computers' data generated at a particular timestamp is reported to you. You are to determine the minimum number of cars that have faulty data.
Input
Each test case begins with an integer N (1<=N<=1000), the number of cars on a track. The next N lines each has two integers -a & b (0<=a,b<=1500) for a particular car.
The last test case is followed by a line with a single 0 indicating the end of input.
Output
For each test case, print a line in the format, “Case X: Y”, whereX is the case number & Y is the minimum number of cars that must have faulty data according to the report.
Sample Input Output for Sample Input
4
2 2
0 0
0 2
3 1
1
1 1
0
Case 1: 3
Case 2: 1
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;const int maxn = 2010;int dp[maxn][maxn];int vis[maxn][maxn] = {0}, v , s;struct car{int p1 , p2;car(int a = 0, int b = 0){p1 = a , p2 = b;}}C[maxn];int N;bool cmp(car c1 , car c2){if(c1.p2 == c2.p2){return c1.p1<c2.p1;}return c1.p2<c2.p2;}void initial(){s = 0;}void readcase(){int f , b , cur = 1;for(int i = 1;i <= N;i++){scanf("%d%d" , &f , &b);if(f+b >= N) s++;else C[cur++] = car(f+1 , N-b);}sort(C+1 , C+cur , cmp);}int DP(int k ,int i , int sum){if(k > N-s) return 0;if(vis[k][i] == v) return dp[k][i];vis[k][i] = v;int tem = 1e9;if(C[i].p1 == C[k].p1 && C[i].p2 == C[k].p2 && sum < C[i].p2-C[i].p1+1){dp[k][i] = DP(k+1 , i , sum+1);return dp[k][i];}if(C[i].p2 < C[k].p1){tem = min(DP(k+1 , i , sum)+1 , DP(k+1 , k , 1));}else{tem = min(tem , DP(k+1 , i , sum)+1);}return dp[k][i] = tem;}int main(){int c = 1;v = 1;while(cin >> N && N){initial();readcase();printf("Case %d: %d\n" , c++ , s+DP(1 ,0 , 1));v++;}return 0;}
- uva 11766 Racing Car Computer(DP)
- UVA 11766 - Racing Car Computer(DP)
- uva 11766 - Racing Car Computer(dp)
- Funny Car Racing UVA
- Funny Car Racing UVA
- Funny Car Racing UVA
- uva 12661 - Funny Car Racing
- Uva-12661-Funny Car Racing
- uva 12661 funning car racing
- UVA 12661 Funny Car Racing
- UVa 12661 Funny Car Racing
- uva 12661 Funny Car Racing
- UVA 12661 Funny Car Racing
- UVA 12661Funny Car Racing
- UVA 12661 Funny Car Racing
- UVA 12661 Funny Car Racing(最短路)
- uva 12661 funny car racing dijkstra变形
- UVa #12661 Funny Car Racing (例题11-11)
- 线程的状态
- C语言模拟MATRIX特效
- OCP-1Z0-053-V13.02-612题
- poj 3286 How many 0's? --- 数位dp
- OCP-1Z0-053-200题-33题-612
- uva 11766 Racing Car Computer(DP)
- 黑马程序员 ___java基础10 线程2
- Android OpenGL 教程 第一课
- Spring Security 安全权限管理手册
- 项目二在写的一个网盘管理程序, 目前是半成品, 贴几张图给大家看看.
- Linux学习笔记 - 如何取得自己本機的網卡卡號 (MAC)
- mongoose 5.1版本框架分析
- Android OpenGL 教程 第二课
- C# 调用外部程序,并获取输出和错误信息