zoukankan      html  css  js  c++  java
  • BestCoder Round #32

    PM2.5

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 613    Accepted Submission(s): 326


    Problem Description
    Nowadays we use content of PM2.5 to discribe the quality of air. The lower content of PM2.5 one city have, the better quality of air it have. So we sort the cities according to the content of PM2.5 in asending order.

    Sometimes one city’s rank may raise, however the content of PM2.5 of this city may raise too. It means that the quality of this city is not promoted. So this way of sort is not rational. In order to make it reasonable, we come up with a new way to sort the cityes. We order this cities through the diffrence between twice measurement of content of PM2.5 (first measurement – second measurement) in descending order, if there are ties, order them by the second measurement in asending order , if also tie, order them according to the input order.
     
    Input
    Multi test cases (about 100), every case contains an integer n which represents there are n cities to be sorted in the first line.
    Cities are numbered through 0 to n1.
    In the next n lines each line contains two integers which represent the first and second measurement of content of PM2.5
    The ith line describes the information of city i1
    Please process to the end of file.

    [Technical Specification]
    all integers are in the range [1,100]
     
    Output
    For each case, output the cities’ id in one line according to their order.
     
    Sample Input
    2 100 1 1 2 3 100 50 3 4 1 2
     
    Sample Output
    0 1 0 2 1
     
    Source
     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<cstdlib>
     6 using namespace std;
     7 struct node
     8 {
     9     int num,f,s,c;
    10 };
    11 node city[107];
    12 int ans[107];
    13 int n;
    14 bool cmp(node n1,node n2)
    15 {
    16     if(n1.c!=n2.c) return n1.c>n2.c;
    17      if(n1.s!=n2.s) return n1.s<n2.s;
    18     return n1.num<n2.num;
    19 }
    20 int main()
    21 {
    22   //  freopen("in.txt","r",stdin);
    23     while(~scanf("%d",&n)){
    24         memset(city,0,sizeof(city));
    25         for(int i=0;i<n;i++)
    26         {
    27             city[i].num=i;
    28             scanf("%d%d",&city[i].f,&city[i].s);
    29             city[i].c=city[i].f-city[i].s;
    30         }
    31         sort(city,city+n,cmp);
    32         for(int i=0;i<n;i++)
    33         {
    34             ans[city[i].num]=i;
    35         }
    36         bool ff=1;
    37         for(int i=0;i<n;i++)
    38         {
    39             if(ff) printf("%d",city[i].num),ff=0;
    40             else {
    41                 printf(" %d",city[i].num);
    42             }
    43         }
    44         printf("
    ");
    45     }
    46     return 0;
    47 }

    Negative and Positive (NP)

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 2453    Accepted Submission(s): 605


    Problem Description
    When given an array (a0,a1,a2,an1) and an integer K, you are expected to judge whether there is a pair (i,j)(0ij<n) which makes that NPsum(i,j) equals to K true. Here NPsum(i,j)=aiai+1+ai+2++(1)jiaj
     
    Input
    Multi test cases. In the first line of the input file there is an integer T indicates the number of test cases.
    In the next 2T lines, it will list the data for each test case.
    Each case occupies two lines, the first line contain two integers n and K which are mentioned above.
    The second line contain (a0,a1,a2,an1)separated by exact one space.
    [Technical Specification]
    All input items are integers.
    0<T25,1n1000000,1000000000ai1000000000,1000000000K1000000000
     
    Output
    For each case,the output should occupies exactly one line. The output format is Case #id: ans, here id is the data number starting from 1; ans is “Yes.” or “No.” (without quote) according to whether you can find (i,j) which makes PNsum(i,j) equals to K.
    See the sample for more details.
     
    Sample Input
    2 1 1 1 2 1 -1 0
     
    Sample Output
    Case #1: Yes. Case #2: No.
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<set>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<vector>
     8 using namespace std;
     9 const int mod=1000007;
    10 const int maxn=1000010;
    11 const int add=1000000000;
    12 long long sum1[maxn],sum2[maxn];
    13 int n,k;
    14 struct HASHMAP
    15 {
    16     int head[maxn],next[maxn],sum;
    17     long long value[maxn];
    18     void init()
    19     {
    20         memset(head,-1,sizeof(head));
    21         sum=0;
    22     }
    23     bool check(long long val)
    24     {
    25         int h=(val%mod+mod)%mod;
    26         for(int i=head[h];~i;i=next[i]){
    27             if(value[i]==val) return 1;
    28         }
    29         return 0;
    30     }
    31     bool insert(long long val)
    32     {
    33         int h=(val%mod+mod)%mod;
    34         for(int i=head[h];~i;i=next[i])
    35             if(value[i]==val) return 1;
    36         value[sum]=val;
    37         next[sum]=head[h];
    38         head[h]=sum++;
    39         return 0;
    40     }
    41 }H1,H2;
    42 int main()
    43 {
    44  //  freopen("in.txt","r",stdin);
    45     int t;
    46     scanf("%d",&t);
    47      int value;
    48      int cnt=1;
    49     while(t--){
    50         H1.init();H2.init();
    51         memset(sum1,0,sizeof(sum1));
    52          int sign1=1,sign2=1;
    53          scanf("%d%d",&n,&k);
    54          bool ans=0;
    55          int tt;
    56         H1.insert(0);
    57           for(int i=1;i<=n;i++)
    58           {
    59               scanf("%d",&value);
    60               if(ans==1) continue;
    61              if(sign1==1) sum1[i]=sum1[i-1]+value;
    62              else sum1[i]=sum1[i-1]-value;
    63              if(i%2==0) H1.insert(sum1[i]);
    64               if(H1.check(sum1[i]-k)) ans=1;
    65               sum2[i]=-sum1[i];
    66                if(i%2) H2.insert(sum2[i]);
    67               if(H2.check(sum2[i]-k)) ans=1;
    68               sign1*=-1;
    69           }
    70         if(ans) printf("Case #%d: Yes.
    ",cnt++);
    71         else printf("Case #%d: No.
    ",cnt++);
    72     }
    73     return 0;
    74 }
  • 相关阅读:
    WIN8 下 Hyper-V和Vmware Workstation
    小技巧总结
    工具软件
    php开发入门
    docker的用法总结
    [工具] 同步本地文件夹与VPS中的文件夹
    读书笔记之《The Art of Readable Code》Part 3
    读书笔记之《The Art of Readable Code》Part 2
    正则表达式小试牛刀
    读书笔记之《The Art of Readable Code》part 1
  • 原文地址:https://www.cnblogs.com/codeyuan/p/4338597.html
Copyright © 2011-2022 走看看