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 are 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, (The number of cars in front of him) & (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 - 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”, where X 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 <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int ww[][];
int main()
{
int t,n,i,j,x,y,dp[];
t=;
while(scanf("%d",&n),n)
{
memset(ww,,sizeof(ww));
memset(dp,,sizeof(dp));
for(i=; i<n; i++)
{
scanf("%d%d",&x,&y);
if(x+y>=n)continue;
if(ww[x+][n-y]==n-y-x)continue;
ww[x+][n-y]++;
}
for(i=; i<=n; i++)
for(j=; j<i; j++)
dp[i]=max(dp[i],dp[j]+ww[j+][i]);
printf("Case %d: %d\n",t++,n-dp[n]);
}
}

Racing Car Computer dp的更多相关文章

  1. UVA 11766 Racing Car Computer --DP

    题意:电脑记录了某一时刻每个赛车的前面和后面个有多少辆车(多个车并排时在别的车那只算一辆),问最少有多少个不合理的数据. 分析:看到n<=1000时,就尽量往DP上想吧. 每输入一组数据a,b, ...

  2. hdu 2196 Computer(树形DP)

    Computer Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  3. HDU 2136:Computer(树形DP)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=2196 Computer     Description A school bought the fi ...

  4. HDU 2196 树形DP Computer

    题目链接:  HDU 2196 Computer 分析:   先从任意一点开始, 求出它到其它点的最大距离, 然后以该点为中心更新它的邻点, 再用被更新的点去更新邻点......依此递推 ! 代码: ...

  5. SGU 149. Computer Network( 树形dp )

    题目大意:给N个点,求每个点的与其他点距离最大值 很经典的树形dp...很久前就想写来着...看了陈老师的code才会的...mx[x][0], mx[x][1]分别表示x点子树里最长的2个距离, d ...

  6. HDU 2196.Computer 树形dp 树的直径

    Computer Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  7. soj1166. Computer Transformat(dp + 大数相加)

    1166. Computer Transformat Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description A sequenc ...

  8. hdu2196 Computer【树形DP】【换根法】

    Computer Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  9. hdu 2196(Computer 树形dp)

    A school bought the first computer some time ago(so this computer's id is 1). During the recent year ...

随机推荐

  1. POI单元格添加公式以及读取公式结果的值

    POI提供了为单元格添加条件样式的方法,但是我并没有找到获取单元格改变后样式的方法,获取到样式依旧是没有改变之前的. 比如为单元格添加条件样式用于监听单元格值是否被修改,如果单元格值被修改那么字体颜色 ...

  2. Ext.grid.EditorGridPanel联动设置单元格是否可以编辑和背景色

    listeners:{ "beforeedit":function(iEventobj){ var col = iEventobj.row;//获取行 var record = i ...

  3. switch实现一个两数的运算

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. boost::pool 库速记

    使用示例 #include <functional> #include <iostream> #include <boost/pool/pool.hpp> #inc ...

  5. [js高手之路]深入浅出webpack教程系列7-( babel-loader,css-loader,style-loader)的用法

    什么是loader呢,官方解释为文件的预处理器,通俗点说webpack在处理静态资源的时候,需要加载各种loader,比如,html文件,要用html-loader, css文件要用css-loade ...

  6. h5的video标签

    在video标签中,我们可以使用属性:videoWidth & videoHeight,它获取的是video的宽度和高度(媒体本身). 虽然不能直接使用,但是可以通过计算宽高比得到 video ...

  7. MPLS VPN随堂笔记2

    深入理解ospf 理解MPLS VPN 中对OSPF 层次化设计的补充 supper backbone area 2:理解MPLS VPN 中OSPF 的区域设计概念 3:理解MPLS VPN 中OS ...

  8. Java 第七周总结

    1. 本周学习总结 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 我们知道ArrayList是允许重复的,有序的元素的集合,但当我们想用它来放 ...

  9. Linux如何设置dns

    首先打开dns设置文档 空的dns文档如图所示 键入图片中的文本保存即可设置了自己的dns 保存后推出即可.

  10. 《JAVA程序设计》第10周学习总结

    1. 本章学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常与多线程相关内容. 2. 书面作业 1.finally 题目4-2 1.1 截图你的提交结果(出现学号) 1.2 4-2中fin ...