Ferries Wheel
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 56 Accepted Submission(s): 29
Problem Description
The Ferries Wheel is a circle,rounded by many cable cars,and the cars are numbered
1,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 invites N 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,the 1st 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.
![](https://i-blog.csdnimg.cn/blog_migrate/37d5729a2b54a5b2e1ab331b931f6f86.jpeg)
Today,Misaki invites N 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,the 1st 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.
Input
There are many test cases.
For each case,the first line is a integer N(1<=N<=100) means Misaki has invited N friends,and the second line contains N integers val1,val2,...valN , the val[i] means the ith friend's cable car's value.
(0<=val[i]<= INT_MAX).
The INT_MAX is 2147483647 .
For each case,the first line is a integer N(1<=N<=100) means Misaki has invited N friends,and the second line contains N integers val1,val2,...valN , the val[i] means the ith friend's cable car's value.
(0<=val[i]<= INT_MAX).
The INT_MAX is 2147483647 .
Output
For each test case, first output Case #X: ,then output the answer, if there are only one cable car, print "-1";
Sample Input
3 1 2 3 5 1 2 3 5 7 6 2 3 1 2 7 5
Sample Output
Case #1: 1 Case #2: 2 Case #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.
想用标记法去重,但是明显普通一维数组不够大因为数据很大。。。。用vetor还不如直接暴力去重勒~
这里注意会爆int。。很坑很坑的一道题~
这里思路很简单,直接排序去重,然后模拟有一和相等次就亲一次就完事了:
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define ll long long int
int const inf=2147483647;
ll a[105];
ll b[105];
int ha[2147483647];
int main()
{
int n;
int kase=0;
while(~scanf("%d",&n))
{
memset(ha,0,sizeof(ha));
int output=0;
for(int i=1;i<=n;i++)
{
scanf("%I64d",&a[i]);
}
sort(a+1,a+n+1);
int cont=0;
int weizi=1;
a[n+1]=-1;
for(int i=1;i<=n;i++)
{
if(a[i]==a[i+1])
cont++;
else
{
b[weizi]=a[i];
ha[weizi++]=cont;
if(i!=n)
cont=0;
}
}
if(cont==n-1)
{
printf("Case #%d: -1\n", ++kase);
continue;
}
b[0]=b[weizi-1];
b[weizi]=b[1];
ha[0]=ha[weizi-1];
ha[weizi]=ha[1];
for(int i=1;i<weizi;i++)
{
if((b[i]+b[i-1])%inf==b[i+1])
{
output++;
output+=ha[i];
}
}
printf("Case #%d: %d\n",++kase,output);
}
}