zoukankan      html  css  js  c++  java
  • Racing Car Computer dp

    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
    ",t++,n-dp[n]);
    26     }
    27 }
    View Code
  • 相关阅读:
    Linq增删查改
    ObjectiveC 的一些记录
    MAX+VC版的RenderMonkey
    PHP校验身份证是否合法
    将小程序scene中的字符串转为对象
    使用JavaScript与Servlet实现客户端与服务器端验证
    分析jdbc程序的编写步骤和原理
    解析Tomcat生成源代码分析javaBean与对象的生成关系
    《Python基础教程》要点(十):充电时刻:导入模块
    《Python基础教程》要点(七):更加抽象:类
  • 原文地址:https://www.cnblogs.com/ERKE/p/3646955.html
Copyright © 2011-2022 走看看