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

题目意思:给出 n 个人坐的缆车值,假设有 k 个缆车,缆车值 A[i] 需要满足:
A[i−1]<A[i]<A[i+1](1<i<K)。现在要求的是,有多少人满足,(他坐的缆车的值 + 他左边缆车的值) % INT_MAX == 他右边缆车的值。

  首先好感谢出题者的样例三,否则真的会坑下不少人。即同一部缆车可以坐多个人。由于缆车的值是唯一的,所以可以通过排序先排出缆车的位置。求出满足条件的缆车的值,然后统计有多少人坐了即可。

  一开始做的时候很不细心,出现runtime error,因为开了个vis[]数组来统计每部缆车坐的人数了,数据量是2147483647,很明显是错的。

  然后就是考虑题目中的输出 -1(只有一部缆车) 情况遗漏了,n == 1只是其中一种情况!因为缆车的值是独一无二的,那么排序后如果val[1] == val[n] 就能覆盖缆车只有一部的所有情况了。

  最后就是没有用 long long (或 __int 64) 保存数据了。因为缆车的值最大是 2147483647,如果它左边的值(要相加嘛)是 1 以上,就会爆 int 了。

  细心细心细心。。。细心。。。。。。

  (1)简单版(学人写的)

  

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std; const int maxn = + ;
const __int64 I_MAX = ;
__int64 a[maxn]; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE int n, cas = ;
while (scanf("%d", &n) != EOF) {
for (int i = ; i <= n; i++)
scanf("%I64d", &a[i]);
sort(a+, a++n);
if (a[] == a[n]) { // 只有一部缆车的情况
printf("Case #%d: -1\n", ++cas);
continue; // 不要也行
}
else {
int ans = ;
a[] = a[n], a[n+] = a[]; for (int i = ; i <= n; i++) {
int l = i, r = i;
while (a[i] == a[l] && l >= ) // 定位左边的缆车值
l--;
while (a[i] == a[r] && r <= n+) // 定位右边的缆车值
r++;
if ((a[i]+a[l]) % I_MAX == a[r])
ans++;
}
printf("Case #%d: %d\n", ++cas, ans);
}
}
return ;
}

(2)错了10次以上终于改正确的= =

  

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + ;
const __int64 NUM = ; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
int n, cas = ;
while (scanf("%d", &n) != EOF) {
__int64 val[maxn];
__int64 tmp[maxn];
for (int i = ; i < n; i++) {
scanf("%I64d", &tmp[i]);
}
sort(tmp, tmp+n);
if (tmp[] == tmp[n-])
printf("Case #%d: -1\n", ++cas);
else {
int c = ;
for (int i = ; i < n; i++) {
while (tmp[i] == tmp[i+] && i < n)
i++;
val[c++] = tmp[i];
} int ans = ;
if ((val[] + val[c-]) % NUM == val[]) {
for (int j = ; j < n; j++) {
if (tmp[j] == val[])
ans++;
}
}
if ((val[c-] + val[c-]) % NUM == val[] && val[c-] != val[]) {
for (int j = n-; j >= ; j--) {
if (tmp[j] == val[c-])
ans++;
}
}
for (int i = ; i < c-; i++) {
if ((val[i] + val[i-]) % NUM == val[i+] && val[i] != val[] && val[i] != val[c-]) {
for (int j = i; j < n; j++) {
if (tmp[j] == val[i])
ans++;
}
}
}
printf("Case #%d: %d\n", ++cas, ans);
}
}
return ;
}

Valentine's Day Round 1001.Ferries Wheel(hdu 5174)解题报告的更多相关文章

  1. BestCoder12 1001.So easy(hdu 5058) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5058 (格式有点问题,为了方便阅读---整个复制下来吧) 题目意思:给出两个长度都为 n 的集合你,问 ...

  2. BestCoder3 1001 Task schedule(hdu 4907) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4907 题目意思:给出工作表上的 n 个任务,第 i 个任务需要 ti 这么长的时间(持续时间是ti ~ ...

  3. BestCoder5 1001 Poor Hanamichi(hdu 4956) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956(它放在题库后面的格式有一点点问题啦,所以就把它粘下来,方便读者观看) 题目意思:给出一个范围 [ ...

  4. "1001. A+B Format (20)" 解题报告

    Github : git@github.com:Circlecos/object-oriented.git PDF Of Markdown : "1001. A+B Format (20)& ...

  5. BestCoder8 1001.Summary(hdu 4989) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4989 题目意思:给出 n 个数,然后将这些数两两相加,得到 n*(n-1) /2 对和,把重复的和去掉 ...

  6. BestCoder24 1001.Sum Sum Sum(hdu 5150) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5150 题目意思:就是直接求素数. 不过 n = 1,也属于答案范围!!只能说,一失足成千古恨啊---- ...

  7. BestCoder19 1001.Alexandra and Prime Numbers(hdu 5108) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5108 题目意思:给出一个数正整数 N,N <= 1e9,现在需要找出一个最少的正整数 M,使得 ...

  8. BestCoder17 1001.Chessboard(hdu 5100) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5100 题目意思:有一个 n * n 的棋盘,需要用 k * 1 的瓷砖去覆盖,问最大覆盖面积是多少. ...

  9. BestCoder13 1001.Beautiful Palindrome Number(hdu 5062) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5062 题目意思:给出 N,找出 1 - 10^N 中满足 Beautiful Palindrome N ...

随机推荐

  1. php加速运行优化

    一个系统的运行性能,除了程序本身要写的完善,还有要看php本身的一些问题,对于php的运行优化,主要有这些加速器:wincache,xcache,ZendOPcache,eAccelerator加速器 ...

  2. 解析posix与perl标准的正则表达式区别 ---PHP

        正则表达式(Regular Expression,缩写为regexp,regex或regxp),又称正规表达式.正规表示式或常规表达式或正规化表示法或正规表示法,是指一个用 来描述或者匹配一系 ...

  3. MySQL的Order By Rand()的效率问题

    MySQL很多时候需要获取随机数据,举个例子,要从tablename表中随机提取一条记录,大家一般的写法就是: 但是,后来我查了一下MYSQL的官方手册,里面针对RAND()的提示大概意思就是,在OR ...

  4. #define 中#和##的作用

    #的作用是把后面的参数变成一个字符串. 如,#define f(a) #a f(hello world)相当于"hello world": ##的作用是把两个字符串连接起来. 如, ...

  5. CSS只是要点-收集

    1. CSS 浮动定位详解 请点击:css浮动定位详解

  6. Mac安装OpenCV

    安装过程参考这篇文章Mac平台上OpenCV开发环境搭建 也可以参考文档官网上的安装文档Installation in Linux(不知道为什么没有Installation in Mac...) 我的 ...

  7. mysql 修改表结构

    alter table 表名 modify column 字段名 varchar(数量); 将varchar(50)改为255 alter table 表名 modify column 字段名 var ...

  8. select根据text选择项与select其它操作

    // 6.设置select中text="paraText"的第一个Item为选中 function jsSelectItemByValue(objSelect, objItemTe ...

  9. Xcode 7 App Transport Security has blocked a cleartext HTTP 报错解决办法

    Xcode 7 创建新项目用到 UIWebView 发送请求时,报下面的错: “App Transport Security has blocked a cleartext HTTP (http:// ...

  10. iOS开发——UI进阶篇(三)自定义不等高cell,如何拿到cell的行高,自动计算cell高度,(有配图,无配图)微博案例

    一.纯代码自定义不等高cell 废话不多说,直接来看下面这个例子先来看下微博的最终效果 首先创建一个继承UITableViewController的控制器@interface ViewControll ...