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 }
  • 相关阅读:
    完美图解教程 Linux环境VNC服务安装、配置与使用
    c语言中<stdbool.h>的使用
    UNIX文件结构(转自UNIX/AIX操作系统基础教程)
    umask
    在AIX环境为Oracle表空间增加裸设备(逻辑卷)
    面的面积大小合线的长度的判断。
    不用新浪博客了。以后的日常感悟也在这里写了, 新浪太烂了。 (感叹也没用,什么都写不出来。 )
    轴心工具的做法。
    选择因素随机的判断。
    上面发的那个完整版变量还有问题,难道我不是用英文输入法, 电脑不说谎 ,看来我是大意了。下面是最终版。
  • 原文地址:https://www.cnblogs.com/cssystem/p/2912686.html
Copyright © 2011-2022 走看看