750C New Year and Rating
2017-02-18 10:29
330 查看
题目链接:
http://codeforces.com/problemset/problem/750/C
题解:
主人公开始水codeforces,一共分为两个阶段,div2的分数没有下限,但是不能超过1899,div1的分数没有上限,但是下限为1900,给你n次比赛的信息。每次都给出改动的分数以及他分数的在哪个阶段,问你他的最高分是多少。
我们可以先假设开始时的分数为x,当第一次的为div1的时候,它的区间为[1900,inf],当为div2的时候,区间为[-inf,1899]。当他下一次为div1的时候,我们可以推出:x+num1+num2+num3……<=1900,当为div2的时候,x+num1+num2+num3……>=1899,因此我们可以再推导得:
当为div1的时候:x<=1900-num1-num2-num3……
当为div2的时候:x>=1899-num1-num2-num3……
因此当为div1的时候,我们只要维护一下最小值,当为div2的时候维护一下最大值(理由:不等式)
其他的情况就不说了,直接看代码就行了。
代码:
http://codeforces.com/problemset/problem/750/C
题解:
主人公开始水codeforces,一共分为两个阶段,div2的分数没有下限,但是不能超过1899,div1的分数没有上限,但是下限为1900,给你n次比赛的信息。每次都给出改动的分数以及他分数的在哪个阶段,问你他的最高分是多少。
我们可以先假设开始时的分数为x,当第一次的为div1的时候,它的区间为[1900,inf],当为div2的时候,区间为[-inf,1899]。当他下一次为div1的时候,我们可以推出:x+num1+num2+num3……<=1900,当为div2的时候,x+num1+num2+num3……>=1899,因此我们可以再推导得:
当为div1的时候:x<=1900-num1-num2-num3……
当为div2的时候:x>=1899-num1-num2-num3……
因此当为div1的时候,我们只要维护一下最小值,当为div2的时候维护一下最大值(理由:不等式)
其他的情况就不说了,直接看代码就行了。
代码:
#include <cmath> #include <cstdio> #include <map> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define met(a,b) memset(a,b,sizeof(a)) #define inf 0x3f3f3f3f typedef long long ll; int main() { int n; scanf("%d",&n); int left=-inf,right=inf; int score=0; for(int i=1;i<=n;i++) { int delta,pos; scanf("%d%d",&delta,&pos); if(pos==1) left=max(left,1900-score); else right=min(right,1899-score); score+=delta; } if(left>right) printf("Impossible\n"); else if(right==inf) printf("Infinity\n"); else printf("%d\n",right+score); }
相关文章推荐
- New Year and Rating CodeForces - 750C
- New Year and Rating CodeForces - 750C
- 【codeforces 750C】New Year and Rating(做法2)
- I - New Year and Rating CodeForces - 750C 模拟
- 【codeforces 750C】New Year and Rating
- New Year and Rating CodeForces - 750C
- Codeforces Good Bye 2016 C.New Year and Rating//qduoj 三亿河老师的上分梦想
- Codeforces Good Bye 2016 C. New Year and Rating(模拟)
- C. New Year and Rating
- codeforces 750-C. New Year and Rating(模拟)
- Good Bye 2016 C. New Year and Rating(二分)
- codeforces goodbye 2016 C. New Year and Rating
- Good Bye 2016 C. New Year and Rating(二分)
- Good Bye 2016 C. New Year and Rating(模拟)
- Codeforces 750 C New Year and Rating
- New Year and Rating
- GoodBye 2016 C. New Year and Rating 详解(维护不等式)
- Good Bye 2017-D. New Year and Arbitrary Arrangement
- hpu暑假训练G - New Year and Days【数学】
- VJ2-New Year and Counting Cards