hdu 5174(计数)
Ferries Wheel
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1651 Accepted Submission(s): 494

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.
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.
1 2 3
5
1 2 3 5 7
6
2 3 1 2 7 5
Case #2: 2
Case #3: 3
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.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <math.h>
using namespace std;
const int N = ;
typedef long long LL;
const LL mod = ;
LL val[N];
int cnt[N];
int main()
{
int n;
int t = ;
while(scanf("%d",&n)!=EOF){
memset(cnt,,sizeof(cnt));
for(int i=;i<=n;i++){
scanf("%lld",&val[i]);
}
sort(val+,val++n);
int k =;
int num=;
cnt[num]++;
for(int i=;i<=n;i++){
if(val[i]==val[i-]){
cnt[num]++;
}else{
num++;
cnt[num]++;
val[k++] = val[i];
}
}
printf("Case #%d: ",t++);
k--;
if(k==){
printf("-1\n");
continue;
}
int ans = ;
for(int i=;i<=k;i++){
if(i==){
if((val[]+val[k])%mod==val[]) ans+=cnt[];
}else if(i==k){
if((val[k-]+val[k])%mod==val[]) ans+=cnt[k];
}else{
if((val[i]+val[i-])%mod==val[i+]) ans+=cnt[i];
}
}
printf("%d\n",ans);
}
return ;
}
hdu 5174(计数)的更多相关文章
- Valentine's Day Round 1001.Ferries Wheel(hdu 5174)解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5174 题目意思:给出 n 个人坐的缆车值,假设有 k 个缆车,缆车值 A[i] 需要满足:A[i−1] ...
- hdu 5116 计数
题目大意:给你n个点, n个点的坐标都在200以内,让你统计不相交的两个L形的种数,且L形的两条边长的gcd = 1. 思路:用二维树状数组维护点的信息,然后划分区块进行统计,题解是用总的减去相交的, ...
- hdu 5072 计数+容斥原理
/* 题意: 给出n个数(n<100000), 每个数都不大于100000,数字不会有重复.现在随意抽出3个,问三个彼此互质 或者 三个彼此不互质的数目有多少. 思路: 这道题反着想,就是三个数 ...
- hdu 5174 Ferries Wheel
摩天轮是一个环,周围围绕着一些缆车.每个缆车按顺序编号为1,2,3...K-1,K1,2,3...K−1,K而且每个缆车也拥有一个唯一的值且保证A[i-1] < A[i] < A[i+1] ...
- HDU 5174
题意有点不明白,因为MAX为int最大值,推测为64位,AC #include <cstdio> #include <iostream> #include <cstrin ...
- BestCoder Valentine's Day Round
昨晚在开赛前5分钟注册的,然后比赛刚开始就掉线我就不想说了(蹭网的下场……),只好用手机来看题和提交,代码用电脑打好再拉进手机的(是在傻傻地用手机打了一半后才想到的办法). 1001,也就是 hdu ...
- hdu 5868 Polya计数
Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K ...
- hdu 2865 Polya计数+(矩阵 or 找规律 求C)
Birthday Toy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- [hdu 6184 Counting Stars(三元环计数)
hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...
随机推荐
- linux 下端口进程的查看
1.netstat -tunlp : 会显示所有端口和所有对应的程序 /netstat -tln:也可显示被占用的端口 netstat -tln 1.1 netstat -tunlp |gre ...
- 创建带maven的javaWeb项目
1File——Maven——maven-archtypes-webapp GroupId:表示项目组织唯一标识符 ArtifacrId:表示项目唯一标识符 例如项目名称 Version是项目版本 这三 ...
- 安装软件时出现dll文件缺失
其中一个典型的问题就是安装photoshop时出现缺失文件,如下图 一般遇到这种问题我只能卸掉重装,不过现在学到了一种新的方法.下载相应的文件,将其存放到C:\Windows\System目录下即可. ...
- 【题解】MUTC2013idiots
我是先知道的这题是FFT然后再做的,知道是FFT其实就是个套路题啦.首先,我们容易发现 \(P = \frac{a}{b}\) 其中a表示合法的方案数,而b表示全部的方案数. b的值即为\(C\lef ...
- 遇到问题---java---myeclipse中maven项目引用另一个导致的resource文件混乱的问题
遇到情况 情况是这样的,我们在构建项目时,经常会把一些公用的类和配置提取出去,作为一个公共项目.然后把公共项目作为一个jar包构件引入我们当前的项目中. 引入方式是 <dependency> ...
- makefile使用笔记(一)入门
By francis_hao Mar 2,2017 makefile makefile一个很简单的例子如下,该实例完成在执行make时,将main.c编译成可执行文件main的功能. 各项的含义 ...
- mysql5.7.22以上版本忘记密码时这样修改
1.关闭mysql服务 net stop mysql 2.找到mysql安装路径找到 my.ini 打开在 [mysqld] 下添加 skip-grant-tables 跳过密码校验 3.登陆mysq ...
- JSOI2008 星球大战 [并查集]
题目描述 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系. 某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝国的超级武器,并攻下了星系中几乎所有的星球.这些星球通过特殊的以太隧 ...
- POJ1308:Is It A Tree?(并查集)
Is It A Tree? 题目链接:http://poj.org/problem?id=1308 Description: A tree is a well-known data structure ...
- 用静态工厂的方法实例化bean
//代码如下: package com.timo.domain; public class ClientService { //use static factory method create bea ...