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 n−1.
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 i−1
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

BestCoder Round #32

 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("\n");
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,?an−1) and an integer K, you are expected to judge whether there is a pair (i,j)(0≤i≤j<n) which makes that NP−sum(i,j) equals to K true. Here NP−sum(i,j)=ai−ai+1+ai+2+?+(−1)j−iaj

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 2∗T 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,?an−1)separated by exact one space.
[Technical Specification]
All input items are integers.
0<T≤25,1≤n≤1000000,−1000000000≤ai≤1000000000,−1000000000≤K≤1000000000

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 PN−sum(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.\n",cnt++);
71         else printf("Case #%d: No.\n",cnt++);
72     }
73     return 0;
74 }
时间: 2024-10-18 06:13:33

BestCoder Round #32的相关文章

BestCoder Round #32 1001

http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=570&pid=1001 官方题解: 对于输入的每一行一两个整数作差,按照差值从大到小排序,如果差值一样,按照后面的整数从小到大排序,如果还是一样按照ID从小到大排序. 首先注意下数据范围,大约100组数据,所有整数都在[1,100] 的范围内,即使是用冒泡法或者选择法排序也不会TLE.其次就要考虑如何将城市的标号一并排序,可以构建一个专门保存城市标号的数组,排

BestCoder Round #88

传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <ctime> 5 #include <cmath> 6 #include <iostream> 7 #include <algorithm> 8

BestCoder Round#15 1001-Love

http://acm.hdu.edu.cn/showproblem.php?pid=5082 Love Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 64    Accepted Submission(s): 51 Problem Description There is a Love country with many couples

BestCoder Round #2 1001 (简单处理)

题目链接 题意:给N条信息,每个信息代表有x个人从开始的时间 到 结束的时间在餐厅就餐, 问最少需要多少座位才能满足需要. 分析:由于时间只有24*60 所以把每个时间点放到 数组a中,并标记开始的时间+x, 结束的时间 -x.最后累加比较. 如果时间点太多的时候可以把时间点放到结构体里,排序,然后依次枚举结构体. 1 #include <iostream> 2 #include <cstring> 3 #include <cstdlib> 4 #include <

从lca到树链剖分 bestcoder round#45 1003

bestcoder round#45 1003 题,给定两个点,要我们求这两个点的树上路径所经过的点的权值是否出现过奇数次.如果是一般人,那么就是用lca求树上路径,然后判断是否出现过奇数次(用异或),高手就不这么做了,直接树链剖分.为什么不能用lca,因为如果有树退化成链,那么每次询问的复杂度是O(n), 那么q次询问的时间复杂度是O(qn) 什么是树链剖分呢? 就是把树的边分成轻链和重链 http://blogsina.com.cn/s/blog_6974c8b20100zc61.htmlh

hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 221    Accepted Submission(s): 52 Problem Description A topological sort or topological ordering of a directed

Bestcoder BestCoder Round #28 A Missing number(查找缺失的合法数字)

Problem Description There is a permutation without two numbers in it, and now you know what numbers the permutation has. Please find the two numbers it lose. Input There is a number T shows there are T test cases below. (T<=10T≤10)For each test case

DP BestCoder Round #50 (div.2) 1003 The mook jong

题目传送门 1 /* 2 DP:这题赤裸裸的dp,dp[i][1/0]表示第i块板放木桩和不放木桩的方案数.状态转移方程: 3 dp[i][1] = dp[i-3][1] + dp[i-3][0] + 1; dp[i][0] = dp[i-1][1] + dp[i-1][0]; 4 比赛时二维dp写搓了,主要是边界情况的判断出错,比如dp[3][1] = 1,因为第3块放了木桩,其他地方不能再放,dp[3][0]同理 5 解释一下dp[i][1]的三种情况,可能是前面相隔2个放的方案或者是不放的

计算几何(水)BestCoder Round #50 (div.2) 1002 Run

题目传送门 1 /* 2 好吧,我不是地球人,这题只要判断正方形就行了,正三角形和正五边形和正六边形都不可能(点是整数). 3 但是,如果不是整数,那么该怎么做呢?是否就此开启计算几何专题了呢 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-8 19:54:14 8 * File Name :B.cpp 9 ************