【CUGBACM15级BC第30场 A】hdu 5174 Ferries Wheel
来源:互联网 发布:数控铣床编程四叶草 编辑:程序博客网 时间:2024/06/07 10:19
Ferries Wheel
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1804 Accepted Submission(s): 561
Total Submission(s): 1804 Accepted Submission(s): 561
Problem Description
The Ferries Wheel is a circle,rounded by many cable cars,and the cars are numbered1,2,3...K−1,K in order.Every cable car has a unique value and A[i−1]<A[i ]<A[i+1](1<i<K ) .
Today,Misaki invitesN friends to play in the Ferries Wheel.Every one will enter a cable car. One person will receive a kiss from Misaki,if this person satisfies the following condition: (his/her cable car's value + the left car's value
) % INT_MAX = the right car's value,the1st car’s left car is the kth car,and the right one is 2nd car,the kth car’s left car is the (k−1)th car,and the right one is the 1st car.
Please help Misaki to calculate how many kisses she will pay,you can assume that there is no empty cable car when all friends enter their cable cars,and one car has more than one friends is valid.
Today,Misaki invites
) % INT_MAX = the right car's value,the
Please help Misaki to calculate how many kisses she will pay,you can assume that there is no empty cable car when all friends enter their cable cars,and one car has more than one friends is valid.
Input
There are many test cases.
For each case,the first line is a integerN(1<=N<=100) means Misaki has invited N friends,and the second line contains N integers val 1,val2,...valN , the val [i ] means the ith friend's cable car's value.
(0<=val [i]<= INT_MAX).
The INT_MAX is2147483647 .
For each case,the first line is a integer
The INT_MAX is
Output
For each test case, first output Case #X: ,then output the answer, if there are only one cable car, print "-1";
Sample Input
31 2 351 2 3 5 762 3 1 2 7 5
Sample Output
Case #1: 1Case #2: 2Case #3: 3HintIn the third sample, the order of cable cars is {{1},{2}, {3}, {5}, {7}} after they enter cable car,but the 2nd cable car has 2 friends,so the answer is 3.
题意:有n个朋友,每个朋友可能在k个车厢里的任一个,每个车厢权值是递增的
现在问你,有多少给满足(本身权值+左边权值)%INF=右边权值
思路:因为车厢是递增的,排完序后去重,记下去重后每个权值的个数,表示这个车厢的人的个数,然后直接O(n)枚举一遍即可
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>using namespace std;#define N 150#define mod 2147483647long long a[N], num[N];int main(){ int n, hh = 1; while (cin >> n) { for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + 1 + n); int cnt = 1; num[1] = 1; for (int i = 2; i <= n; i++) { if (a[i] != a[i - 1]) { a[++cnt] = a[i]; num[cnt] = 1; } else { num[cnt]++; } } long long ans = 0; for (int i = 1; i <= cnt; i++) { int l, r; if (i == 1) { l = cnt; } else { l = i - 1; } if (i == cnt) { r = 1; } else { r = i + 1; } if ((a[i] + a[l]) % mod == a[r]) { ans += num[i]; } } if (cnt == 1) { printf("Case #%d: -1\n", hh++); } else { printf("Case #%d: %lld\n", hh++, ans); } } return 0;}
阅读全文
0 0
- 【CUGBACM15级BC第30场 A】hdu 5174 Ferries Wheel
- 【CUGBACM15级BC第15场 A】hdu 5083 Love
- 【CUGBACM15级BC第17场 A】hdu 5100 Chessboard
- 【CUGBACM15级BC第23场 A】hdu 5146 Sequence
- 【CUGBACM15级BC第8场 A】hdu 4989 Summary
- 【CUGBACM15级BC第31场 A】hdu 5178 pairs
- 【CUGBACM15级BC第1场 A】hdu 4857 逃生
- 【CUGBACM15级BC第12场 A】【STL】hdu 5058 So easy
- 【CUGBACM15级BC第11场 A】hdu 5054 Alice and Bob
- 【CUGBACM15级BC第13场 A】hdu 5062 Beautiful Palindrome Number
- 【CUGBACM15级BC第18场 A】hdu 5104 Primes Problem
- 【CUGBACM15级BC第20场 A】hdu 5123 who is the best?
- 【CUGBACM15级BC第19场 A】hdu 5108 Alexandra and Prime Numbers
- 【CUGBACM15级BC第21场 A】hdu 5138 CET-6 test
- 【CUGBACM15级BC第22场 A】hdu 5142 NPY and FFT
- 【CUGBACM15级BC第24场 A】hdu 5150 Sum Sum Sum
- 【CUGBACM15级BC第24场 C】hdu 5152 A Strange Problem
- 【CUGBACM15级BC第25场 A】hdu 5154 Harry and Magical Computer
- jsp页面 时间的展示
- [NOIP模拟赛]押韵
- php中文件处理函数总结
- Maven项目下update maven后Eclipse报错:java.lang.ClassNotFoundException- ContextLoaderL
- JAVA中进程、线程
- 【CUGBACM15级BC第30场 A】hdu 5174 Ferries Wheel
- 软件测试学习5-静态白盒测试
- 不安的思考——技术的价值何在
- 左移操作符重载
- Ubuntu 下vi编辑器上下左右键变为ABCD
- 使用webService调用手机号码归属地
- MySQL 备份-通过原始文件
- linux系统常见目录解释说明
- Android自定义对话框实现QQ退出界面