Sicily 11159. Year Award
来源:互联网 发布:淘宝的地址在哪里设置 编辑:程序博客网 时间:2024/06/03 16:19
11159. Year Award
Constraints
Time Limit: 1 secs, Memory Limit: 256 MB , Special Judge
Description
Melita has just returned from the annual pig slaughter. Don't worry, this is a regular thing in Croatia. The best part was the abundance of food! There was everything, starting from good spicy sausages, ham, black pudding, up to teewurst, top quality bacon and ?varci, all with warm white bread and butter. After these appetizers, it was the perfect time to whip up a deep pot full of sarma (Melita ate twentyish of them) as well as a large platter of fine roast pork, so soft that it almost melts in your mouth. They watered all of this down with copious gulps of the best dry white wine that made them even hungrier.
Input
The first line of input contains an integer N (2 ≤ N ≤ 1000), the number of competitors for the Man of the Year award.
Output
Sample Input
样例1:37 13 210 0样例2:32 14 00 3样例3:515 46 712 59 61 7
Sample Output
样例1:10.5样例2:-1样例3:87
Hint
Problem Source
2014年每周一赛第五场
题意就是求出一个x,使得a[i] + (b[i] / sum) * x >= a[i + 1] + (b[i + 1] / sum) * x,其中i从0到n-1,sum是所有b[i]的和,化简公式可以发现对于i从0到n-1,每个上述不等式都能得到x的一个范围,对于每个范围取交集即可。
这题测试样例比较坑,怒交20次才得出下面正确的- -。
#include <algorithm>#include <iostream>#include <string>#include <stdio.h>#include <queue>#include <string.h>#include <vector>#include <iomanip>#include <map>#include <stack>#include <functional>#include <list>using namespace std;#define INF 2000000000int main() { //std::ios::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); vector<int> b(n); long long int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; sum += b[i]; } double up = 10000000.0, down = 0; bool impossible = false; for (int i = 0; i < n - 1; i++) { if (b[i + 1] - b[i] > 0) { double newUp = double(sum * (long long)(a[i] - a[i + 1])) / (double)(b[i + 1] - b[i]); if (newUp < up) up = newUp; } else if (b[i + 1] - b[i] < 0) { double newDown = double(sum * (long long)(a[i] - a[i + 1])) / (double)(b[i + 1] - b[i]); if (newDown > down) down = newDown; } else if (a[i] < a[i + 1]) { cout << -1 << endl; return 0; } } if (down <= up) printf("%lf\n", (up + down) / 2); else cout << -1 << endl; //getchar(); //getchar(); return 0;}
- Sicily 11159. Year Award
- Sicily 2015 A New Year Gift
- Sicily 2015. A New Year Gift
- Sicily 2015 A New Year Gift
- Sicily 2015. A New Year Gift
- sicily 2015 A New Year Gift
- YEAR
- year
- My Award
- AWARD BIOS
- Jolt Award
- Turing Award
- JOLT Award 颁奖
- Award BIOS报警
- AWARD BIOS设置详解
- MVP 2008 Award
- AWARD BIOS设置详解
- 抽奖程序 Award
- Java与C++的微妙
- LeetCode OJ Longest Consecutive Sequence
- LeetCode OJ Balanced Binary Tree
- 527B. Error Correct System【string】
- 数控系统_01
- Sicily 11159. Year Award
- 用输入输出流从res/raw中读取信息
- LeetCode OJ Find Minimum in Rotated Sorted Array
- 历届试题 连号区间数 (找规律+枚举)
- java解压Zip压缩包
- nyoj34 韩信点兵
- 观《超能陆战队》未来的“机器人设计师”的必备装备
- Calculator
- android sharedpreferences小谈