Valentine's Day Round 1001 Ferries Wheel
来源:互联网 发布:搞怪的淘宝收件人名字 编辑:程序博客网 时间:2024/06/07 07:09
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5174
说实话没怎么看懂题意。后来按照自己理解写了一发。
我的理解是这样。输入n个人的价值后,每个人去找缆车,只能上与自己价值相同的缆车。所以刚开始我先对每种价值统计人数,然后对所以不同价值的缆车排序后,判断是否满足条件。
输入的价值存在val[]数组里面,统计后存在arr[][]数组中。
例如
6
2 3 1 2 7 5
则 先对val数组排序,后得
然后统计
注意若arr中只有一个行的话,直接输出-1,而不是n==1输出-1
然后都arr[i][0]做判断,若满足就加上arr[i][1]
代码如下
#include <iostream>#include <iomanip>#include <cstdio>#include <algorithm>#include <cmath>#include <queue>#include <vector>#include <stack>#include <string>#include <cstring>using namespace std;typedef long long ll;const int maxn=11111111;const int INF=0x7fffffff;const int mod=1e7+7;#define LSON l,m,rt<<1#define RSON m+1,r,rt<<1|1#define ESP 1e-7ll val[105], arr[105][2];int main() { int n, n_case=0; while(scanf("%d", &n)!=EOF) { printf("Case #%d: ", ++n_case); for(int i=0;i<n;i++) scanf("%lld", &val[i]); sort(val, val+n); memset(arr, 0, sizeof(arr)); int k=1; arr[0][0]=val[0]; arr[0][1]++; for(int i=1;i<n;i++) { if(val[i]==arr[k-1][0]) arr[k-1][1]++; else { arr[k][0]=val[i]; arr[k++][1]=1; } } if(k==1) { printf("%d\n", -1); continue; } int sum=0; if((arr[0][0]+arr[k-1][0])%INT_MAX==arr[1][0]) sum+=arr[0][1]; if((arr[k-1][0]+arr[k-2][0])%INT_MAX==arr[0][0]) sum+=arr[k-1][1]; for(int i=1;i<k-1;i++) if((arr[i][0]+arr[i-1][0])%INT_MAX==arr[i+1][0]) sum+=arr[i][1]; printf("%d\n", sum); } return 0;}
0 0
- Valentine's Day Round 1001 Ferries Wheel
- [Bestcoder] Valentine's Day Round 1001 - Ferries Wheel | HDU 5174
- HDU 5147 Ferries Wheel(暴力 数组)——BestCoder Valentine's Day Round
- 【BestCoder】#Valentine's Day Round
- BestCoder #Valentine's Day Round 1001 || hdu 5174
- Valentine's Day Round 1002 Misaki's Kiss again
- Valentine's Day Round 1002 Misaki's Kiss again
- valentine's day
- Valentine's Day
- St. Valentine's Day
- St.Valentine’s day
- White Valentine's Day
- Valentine's Day
- Valentine's Day Round(HDU BC比赛)
- BestCoder #Valentine's Day Round 1002 || hdu 5175
- Problem F: Valentine's Day
- The first Valentine's Day
- hdu5174---Ferries Wheel
- LeetCode--Count and Say
- 把书读薄之《面向对象葵花宝典》阅读笔记-面向对象基础
- 微博系统,集成新浪开发,有需要的朋友下载
- auto keyword demo
- WCF 入门教程二
- Valentine's Day Round 1001 Ferries Wheel
- 康托展开
- 第二学期 第一周项目一 初识对象阅读材料回答问题
- 交换两个变量的值,不使用第三个变量的四种方法
- 为什么一旦在任务完成前对人说出计划,就难继续顺利执行?
- Valentine's Day Round 1002 Misaki's Kiss again
- 安卓 关于Intent四个属性的总结
- linux下查看网卡信息的命令
- bzoj 1503/tyvj 1581 郁闷的出纳员