zoukankan      html  css  js  c++  java
  • 5.1.7 Zjnu Stadium

    Zjnu Stadium

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 152 Accepted Submission(s): 65

    Problem Description
    In 12th Zhejiang College Students Games 2007, there was a new stadium built in Zhejiang Normal University. It was a modern stadium which could hold thousands of people. The audience Seats made a circle. The total number of columns were 300 numbered 1--300, counted clockwise, we assume the number of rows were infinite.
    These days, Busoniya want to hold a large-scale theatrical performance in this stadium. There will be N people go there numbered 1--N. Busoniya has Reserved several seats. To make it funny, he makes M requests for these seats: A B X, which means people numbered B must seat clockwise X distance from people numbered A. For example: A is in column 4th and X is 2, then B must in column 6th (6=4+2).
    Now your task is to judge weather the request is correct or not. The rule of your judgement is easy: when a new request has conflicts against the foregoing ones then we define it as incorrect, otherwise it is correct. Please find out all the incorrect requests and count them as R.
     

    Input
    There are many test cases:
    For every case:
    The first line has two integer N(1<=N<=50,000), M(0<=M<=100,000),separated by a space.
    Then M lines follow, each line has 3 integer A(1<=A<=N), B(1<=B<=N), X(0<=X<300) (A!=B), separated by a space.

     

    Output
    For every case:
    Output R, represents the number of incorrect request.
     

    Sample Input
    10 10
    1 2 150
    3 4 200
    1 5 270
    2 6 200
    6 5 80
    4 7 150
    8 9 100
    4 8 50
    1 7 100
    9 2 100
     

    Sample Output
    2
    Hint
    Hint: (PS: the 5th and 10th requests are incorrect)

    思路:这道题跟 5.1.8 How Many Answers Are Wrong 一模一样,我只是把y++这句删了就过了。、

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <cstdlib>
     4 #include <algorithm>
     5 #include <cstring>
     6 #include <string>
     7 using namespace std;
     8 
     9 const int maxn=200100;
    10 int f[maxn],sum[maxn],a,b,x,y,fx,fy,n,m,v,ans;
    11 
    12 void close()
    13 {
    14     exit(0);
    15 }
    16 
    17 int find(int k)
    18 {
    19     if (f[k]==k)
    20         return k;
    21     int t=f[k];
    22     f[k]=find(f[k]);
    23     sum[k]+=sum[t];
    24     return f[k];
    25 }
    26 
    27 void work()
    28 {
    29 }    
    30 
    31 void init ()
    32 {
    33     while(scanf("%d %d",&n,&m)!=EOF)
    34      {
    35          ans=0;
    36          if (n==0 && m==0) break;
    37          for (int i=0;i<=n+2;i++)
    38          {
    39              f[i]=i;
    40              sum[i]=0;
    41          }
    42          for (int i=1;i<=m;i++)
    43          {
    44              scanf("%d %d %d",&x,&y,&v);
    45              fx=find(x);
    46              fy=find(y);
    47              if (fx==fy && v+sum[y]!=sum[x])
    48                  ans++;
    49              else
    50                  if(fx!=fy)
    51                  {
    52                      if (fy>fx)
    53                      {
    54                         f[fx]=fy;
    55                         sum[fx]=sum[y]+v-sum[x];
    56                      }
    57                      else
    58                      {
    59                          f[fy]=fx;
    60                          sum[fy]=sum[x]-v-sum[y];
    61                      }
    62                  }
    63          }
    64          printf("%d\n",ans);
    65      }
    66 }
    67 
    68 int main ()
    69 {
    70     init();
    71     work();
    72     close();
    73     return 0;
    74 }
  • 相关阅读:
    C++头文件保护符和变量的声明定义
    ReactNavtive框架教程(2)
    扩展方法使用
    华为0基础——(练习用)挑7
    HTTP Status 500
    屏蔽DataGridView控件DataError 事件提示的异常信息
    POJ 3630 Phone List Trie题解
    【学习总结】数学-向量叉积
    9.1-9.30推荐文章汇总
    Autolayout环境设置任意个数相等间距排列的按钮的方法
  • 原文地址:https://www.cnblogs.com/cssystem/p/2912686.html
Copyright © 2011-2022 走看看