HDU 5174 Ferries Wheel (暴力小模拟)

37 篇文章 0 订阅


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...K1,K in order.Every cable car has a unique value and A[i1]<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 (k1)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 .
 

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: 3
Hint
In 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.
 

Source
Valentine's Day Round

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5174

题目大意:中间加后面对int_max取余等于后面,求满足情况的各个中间集合中的值的和

题目分析:暴力小模拟,只有一个集合时输出-1

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define ll long long
int const MAX = 2147483647;
ll a[105], b[105];
int re[105];

int main()
{
    int n, ca = 1;
    while(scanf("%d", &n) != EOF)
    {
        memset(re ,0 , sizeof(re));
        int ans = 0;
        for(int i = 1; i <= n; i++)
            scanf("%I64d", &a[i]);
        sort(a + 1, a + n + 1);
        int cnt = 0, pos = 1;
        a[n + 1] = -1;
        for(int i = 1; i <= n; i++)
        {
            if(a[i] == a[i + 1])
                cnt++;
            else
            {
                b[pos] = a[i];
                re[pos++] = cnt;
                if(i != n)
                    cnt = 0;
            }
        }
        if(cnt == n - 1)
        {
            printf("Case #%d: -1\n", ca++);
            continue;
        }
        b[0] = b[pos-1];
        b[pos] = b[1];
        re[0] = re[pos-1];
        re[pos] = re[1];
        for(int i = 1; i < pos; i++)
            if((b[i] + b[i - 1]) % MAX == b[i + 1])
            {
                ans ++;
                ans += re[i];
            }
        printf("Case #%d: %d\n", ca++, ans);
    }
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值