Codefroces 750C:New Year and Rating(思维)
http://codeforces.com/contest/750/problem/C
题意:有n场比赛,每场比赛有一个c,代表比赛结束后分数的增长情况,有一个d,代表这场比赛在div1或者div2打。div1 >= 1900,div2 < 1900。求打完这n场比赛后可能得到的最大分数。如果无限大就输出“Inifinity”,如果有矛盾就输出“Impossible”。
思路:官方题解。
For every contest we know that the current rating is x increased by some prefix sum of c_i (changes of rating). If Limak is in the division 1, we have inequality x+prefSum >= 1900 so we have x >= 1900-prefSum. If Limak is in the division 2, we have inequality x_prefSum <= 1899 so it is x <= 1899-prefSum. From this set of inequalities, your task is to find the biggest x satisfying all of them.
设立一个可行的上下限,对每场比赛,更新上下限。设一个初始分数 x,-INF <= X <= INF,处理一个c[i]的前缀和s,如果在div1打的话,只有 x + s >= 1900,才可在div1打,那么分数的下限就是max(low,1900 - s),如果在div2打,只有 x + s <= 1899,才可以才div2打,那么分数的上限是min(high,1899 - s)。最后处理答案,如果一直在div1打,那么分数无穷大,如果 low 和 high 冲突,那么是不可能。否则就是初始的分数上限 + 前缀和s。
昨晚大概也想的是设立一个上下限,但是想的好乱,搞不定。还是要多训练自己的思维能力。
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define INF 0x3f3f3f3f
#define N 200010
typedef long long LL;
int n, c[N], d[N]; int main() {
cin >> n;
int flag = ;
for(int i = ; i <= n; i++)
scanf("%d%d", &c[i], &d[i]);
int left = -INF, right = INF;
int s = ;
for(int i = ; i <= n; i++) {
if(d[i] == ) left = max(left, - s);
if(d[i] == ) right = min(right, - s);
s += c[i];
}
if(right < left) puts("Impossible");
else if(right == INF) puts("Infinity");
else printf("%d\n", right + s);
return ;
}
Codefroces 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 750C】New Year and Rating
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- C. New Year and Rating 差分方程 思维
题意: 一个CF玩家打CF 给出其比赛列表和上分(掉分)情况 ,但是没给初始分 问最后最高分是多少 (情况不存在,或者可能无穷大) 思路: 设初始分为x 那么之前的回合的分数前缀和为sum 如 ...
- Codefroces 628B New Skateboard(数位+思维)
题目链接:http://codeforces.com/contest/628/problem/B 题目大意:给你一段数字串s(1?≤?|s|?≤?3·10^5),求该字符串有多少子串是4的倍数.解题思 ...
- Codeforces Global Round 12 D. Rating Compression (思维,双指针)
题意:给你一长度为\(n\)的数组,有一长度为\(k\ (1\le k \le n)\)的区间不断从左往右扫过这个数组,总共扫\(n\)次,每次扫的区间长度\(k=i\),在扫的过程中,每次取当前区间 ...
- 从Elo Rating System谈到层次分析法
1. Elo Rating System Elo Rating System对于很多人来说比较陌生,根据wikipedia上的解释:Elo评分系统是一种用于计算对抗比赛(例如象棋对弈)中对手双方技能水 ...
- codefroces中的病毒,这题有很深的trick,你能解开吗?
大家好,欢迎阅读周末codeforces专题. 我们今天选择的问题是contest 1419的C题,目前有接近8000的人通过了本题.今天这题的难度不大,但是真的很考验思维,一不小心就会踩中陷阱,我个 ...
- [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序
用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html 目录 马桶排序(令人 ...
- Photoshop、Illustrator思维导图笔记
半年前学习Photoshop时记得的思维导图笔记,可能不是很全,常用的基本都记下了.
随机推荐
- 优惠分摊算法 php版
<?php /* * 优惠分摊,算法很多,这里是从shopnc挖出来,适合优惠条件过滤的算法,实质很简单,但是理解难度还是有一点 * * 一个订单的商品,如果不参与某种活动,需要分摊优惠,一般来 ...
- Sony Z1 flashtool 刷机笔记
第一次硬刷,(相较于recovery的卡刷)差点变成无限重启..记录一些关键步骤: 1 unlock bootloader http://developer.sonymobile.com/unlock ...
- 一步一步来做WebQQ机器人-(五)(发送消息||完结)
× 本篇主要是: 发送QQ消息(to:好友,群),以及对小黄鸡抓包利用它的语言库 本文是WebQQ流程的最后一章 最后一章内容不多但我还是啰嗦,可能对大部分人都已知晓的流程方法我也会介绍一下 前面几个 ...
- ueditor的模板功能
~~项目临时发现kindeditor比ueditor更好用~~ 不过还是回来把ueditor的学习,加一个书签标明一下阶段. 下面写一下ueditor的模板功能,即修改模板,使ueditor自动生成想 ...
- Renci.SshNet在Linux运维的应用
SSH.NET是一个.net的SSH应用库,支持并发.该库最新的代码可以从github上下载下来,比Sharp.SSH更新的频繁.它可以模拟ssh登陆,类似xshell.putty等工具.不过有更多的 ...
- HBASE基础知识
HBASE的集群的搭建HBASE的表设计HBASE的底层存储模型 HBase 是一个高可靠.高性能.面向列.可伸缩的分布式缓存系统.利用HBase 技术可在廉价PC Server上搭建起大规模结构化存 ...
- javascript 函数重载 overloading
函数重载 https://en.wikipedia.org/wiki/Function_overloading In some programming languages, function over ...
- js时间格式化
const formatDate = timestamp => { const date = new Date(timestamp); const m = date.getMonth() + 1 ...
- Leetcode: Validate IP Address
In this problem, your job to write a function to check whether a input string is a valid IPv4 addres ...
- Android 回调接口是啥,回调机制详解(zhuan)
回调函数http://blog.csdn.net/a78270528/article/details/46918601 Android框架 android frame work: http://blo ...