【codeforces 750C】New Year and Rating
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one’s performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division di (i.e. he belonged to this division just before the start of this contest) and his rating changed by ci just after the contest. Note that negative ci denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print “Infinity”. If there is no scenario matching the given information, print “Impossible”.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000).
The i-th of next n lines contains two integers ci and di ( - 100 ≤ ci ≤ 100, 1 ≤ di ≤ 2), describing Limak’s rating change after the i-th contest and his division during the i-th contest contest.
Output
If Limak’s current rating can be arbitrarily big, print “Infinity” (without quotes). If the situation is impossible, print “Impossible” (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak’s current rating, i.e. rating after the n contests.
Examples
input
3
-7 1
5 2
8 2
output
1907
input
2
57 1
22 2
output
Impossible
input
1
-5 1
output
Infinity
input
4
27 2
13 1
-50 1
8 2
output
1897
Note
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating:
Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7.
With rating 1894 Limak is in the division 2. His rating increases by 5.
Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it’s impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
【题目链接】:http://codeforces.com/contest/750/problem/C
【题解】
我用的应该是最蠢的办法了;
敲了180行.
敲到一半我都快要哭出来了。
但是痛苦是有回报的:)
这次代码的注解写的很详细.可以到程序里面具体看;
/*
如果一直都没有出现div2
那就说明全都在div1;
则不管你怎么变都无所谓,都是无限大
如果全都是div2他有一个上限1900
(有可能从div2变成了div1,所以要特判一下)
x=0
然后对x进行ci的变换
记录x的最大值
如果max(x)>=0
则rating为
1899-(max(x)-x)
如果max(x)<0
则rating为
1899+x
有div1和div2夹杂
找最后一个div1和div2的分割点
i c[i] div2
i+1 c[i+1] div1
那就表示第i场比赛的时候
rating<1900
第i+1场比赛的时候rating>1900
ci变化范围是1..100
所以第i场的时候分数范围是
1800..1899
从大到小枚举
ci不在这个范围输出无解
i c[i] div1
i+1 c[i+1] div2
则第i场比赛的时候
rating>=1900
第i+1场比赛的时候rating<1900
第i场比赛的时候rating的范围是1900..1999
ci的话范围是-1..-100
如果ci不在这个范围则也输出无解
时间复杂度就是O(100*N)吧。不会超的.
*/
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int MAXN = 2e5+100;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
struct abc
{
int c,d;
};
int n,nd[3];
abc a[MAXN];
int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);
rep1(i,1,n)
{
rei(a[i].c);rei(a[i].d);
nd[a[i].d]++;
}
if (nd[1]>0 && nd[2]==0)//都是div1
{
puts("Infinity");
return 0;
}
if (nd[1]==0 && nd[2]>0)//都是div2
{
rep2(rating,1999,1900)//最后变成div1的情况
{
int tempr = rating;
bool fi = true;
rep2(j,n,1)
{
tempr+=-a[j].c;
if (tempr>=1900)
{
fi = false;
break;
}
}
if (!fi)
continue;
if (fi)
{
printf("%d\n",rating);
return 0;
}
}
int x = 0,ma = -2100000000,ans;//其他则都在div2
rep1(i,1,n)
{
x+=a[i].c;
ma = max(ma,x);
}
if (ma>=0)//最大值大于0那个时候到达最大1899
ans = 1899-(ma-x);
else//最大值小于0,则总是小于1899的
ans = 1899+x;
cout << ans << endl;
return 0;
}
rep2(i,n,2)
if (a[i].d!=a[i-1].d)
{
if (a[i-1].d==2 && a[i].d==1)//之前是div2涨分到div1
{
rep2(rating,1899,1800)//从大到小枚举打i-1这场比赛之前的分数
{
bool fi = true;
int tempr = rating;
rep2(j,i-2,1)
{
tempr+=(-a[j].c);//看看减回去之后能不能打那场比赛
if (tempr>=1900 && a[j].d==2)
{
fi = false;
break;
}
if (tempr<1900 && a[j].d==1)
{
fi = false;
break;
}
}
if (!fi) continue;
tempr = rating;
rep1(j,i-1,n)//看看打完这场比赛之后是不是真的能打下一场比赛
{
tempr+=a[j].c;
if (tempr>=1900 && a[j+1].d==2)//判断依据是下一场比赛
{
fi = false;
break;
}
if (tempr<1900 && a[j+1].d==1)
{
fi = false;
break;
}
}
if (!fi) continue;
if (fi)
{
printf("%d\n",tempr);
return 0;
}
}
puts("Impossible");
return 0;
}
else
if (a[i-1].d==1 && a[i].d==2)
{
rep2(rating,1999,1900)//打第i-1场比赛之前分数为1900.1999这个区间
{
bool fi = true;
int tempr = rating;
rep2(j,i-2,1)//看看倒回去是不是每场比赛都真的能打
{
tempr+=(-a[j].c);
if (tempr>=1900 && a[j].d==2)
{
fi = false;
break;
}
if (tempr<1900 && a[j].d==1)
{
fi = false;
break;
}
}
if (!fi) continue;
tempr = rating;
rep1(j,i-1,n)//继续往前打
{
tempr+=a[j].c;
if (tempr>=1900 && a[j+1].d==2)//看看下一场比赛能不能打
{
fi = false;
break;
}
if (tempr<1900 && a[j+1].d==1)
{
fi = false;
break;
}
}
if (!fi) continue;
if (fi)
{
printf("%d\n",tempr);
return 0;
}
}
puts("Impossible");
return 0;
}
break;
}
return 0;
}
【codeforces 750C】New Year and Rating的更多相关文章
- 【codeforces 750C】New Year and Rating(做法2)
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 807A】Is it rated?
[题目链接]:http://codeforces.com/contest/807/problem/A [题意] 给你n个人在一场CF前后的rating值; 问你这场比赛是不是计分的 [题解] 如果有一 ...
- 【74.89%】【codeforces 551A】GukiZ and Contest
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- 2018年DDoS攻击全态势:战胜第一波攻击成“抗D” 关键
2018年,阿里云安全团队监测到云上DDoS攻击发生近百万次,日均攻击2000余次.目前阿里云承载着中国40%网站,为全球上百万客户提供基础安全防御.可以说,阿里云上的攻防态势是整个中国攻防态势的缩影 ...
- 使用R拟合分布
使用R拟合分布 几个常用的概率函数介绍 这里,参考R语言实战,以及[Fitting Distribution with R]的附录. 一.认识各种分布的形态 1.1 连续型随机变量的分布 首先,我们来 ...
- AtCoder Regular Contest 084 C - Snuke Festival【二分】
C - Snuke Festival ....最后想到了,可是不应该枚举a[],这样要二重循环,而应该枚举b[],这样只需一重循环... #include<iostream> #inclu ...
- 2019.8.3 [HZOI]NOIP模拟测试12 C. 分组
2019.8.3 [HZOI]NOIP模拟测试12 C. 分组 全场比赛题解:https://pan.baidu.com/s/1eSAMuXk 刚看这题觉得很难,于是数据点分治 k只有1和2两种,分别 ...
- Alpha版本第一周作业
姓名 学号 周前计划安排 每周实际工作记录 自我打分 LTR 61213 1.撰写博客2.分配具体任务并完成个人任务 1.已完成博客撰写2.任务分配完成并继续构思实现方法 95 LHL 61212 完 ...
- Java练习 SDUT-1253_进制转换
进制转换 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 输入一个十进制数N,将它转换成R进制数输出. Input 输入 ...
- OpenKruise - 云原生应用自动化引擎正式开源
2019 年 6 月 24 日至 26 日, 由 Cloud Native Computing Foundation (CNCF) 主办的云原生技术大会 KubeCon + CloudNativeCo ...
- @bzoj - 4709@ 柠檬
目录 @desription@ @solution@ @accepted code@ @details@ @desription@ 一共有 N 只贝壳,编号为 1...N,贝壳 i 的大小为 si. ...
- OpenStack☞HTTP协议
前言 超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.所有的WWW文件都必须遵守这个标准 HTTP是一个基于TCP/IP通信协议 ...
- Getting started with the basics of programming exercises_2
1.编写简单power函数 #include<stdio.h> int power(int m, int n); // test power function int main(void) ...