Racing Car Computer dp

本文介绍了一种用于诊断赛车上新型视觉传感器故障的算法。通过分析赛车计算机报告的数据,该算法可以确定赛道上至少有多少辆车的传感器出现故障。文章还提供了一个示例性的C++实现。

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

  

 

 

 1 #include <algorithm>
 2 #include <iostream>
 3 #include <stdio.h>
 4 #include <string.h>
 5 using namespace std;
 6 int ww[1200][1200];
 7 int main()
 8 {
 9     int t,n,i,j,x,y,dp[1200];
10     t=1;
11     while(scanf("%d",&n),n)
12     {
13         memset(ww,0,sizeof(ww));
14         memset(dp,0,sizeof(dp));
15         for(i=0; i<n; i++)
16         {
17             scanf("%d%d",&x,&y);
18             if(x+y>=n)continue;
19             if(ww[x+1][n-y]==n-y-x)continue;
20             ww[x+1][n-y]++;
21         }
22         for(i=1; i<=n; i++)
23             for(j=0; j<i; j++)
24                 dp[i]=max(dp[i],dp[j]+ww[j+1][i]);
25        printf("Case %d: %d\n",t++,n-dp[n]);
26     }
27 }
View Code

 

 

 

 

 

转载于:https://www.cnblogs.com/ERKE/p/3646955.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值