A. Is it rated?

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

Is it rated?

Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.

Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.

It's known that if at least one participant's rating has changed, then the round was rated for sure.

It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.

In this problem, you should not make any other assumptions about the rating system.

Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.

Input

The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of round participants.

Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 4126) — the rating of the i-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.

Output

If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".

Examples
Input
6 
3060 3060
2194 2194
2876 2903
2624 2624
3007 2991
2884 2884
Output
rated
Input
4 
1500 1500
1300 1300
1200 1200
1400 1400
Output
unrated
Input
5 
3123 3123
2777 2777
2246 2246
2246 2246
1699 1699
Output
maybe
Note

In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.

In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.

In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.

题目链接:http://codeforces.com/contest/807/problem/A

题意:给你n个人在一场CF前后的rating值; 问你这场比赛是不是计分的

分析:如果有一个人的rating变了; 则是计分的; 否则; 按照题目所给的规则判断是maybe还是unrated; O(N^2) ,做法先开两个数组进行比较,看是否相等,然后再进行排序,看是否存在两个非单调递减的数组,此为正解!

下面给出AC代码:

 #include <bits/stdc++.h>
using namespace std;
int a[],b[];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int sum=;
for(int i=;i<=n;i++)
{
scanf("%d%d",&a[i],&b[i]);
if(a[i]==b[i])
sum++;
}
if(sum!=n)
printf("rated\n");
else
{
int ans=;
for(int i=;i<=n;i++)
{
if(a[i]>=a[i+])
ans++;
}
if(ans==n)
printf("maybe\n");
else printf("unrated\n");
}
}
return ;
}

B. T-Shirt Hunt

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt.

Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place p.

Now the elimination round of 8VC Venture Cup 2017 is being held. It has been announced that the Codecraft-17 T-shirt winners will be chosen as follows. Let s be the number of points of the winner of the elimination round of 8VC Venture Cup 2017. Then the following pseudocode will be executed:

i := (s div 50) mod 475 repeat 25 times:     i := (i * 96 + 42) mod 475     print (26 + i)

Here "div" is the integer division operator, "mod" is the modulo (the remainder of division) operator.

As the result of pseudocode execution, 25 integers between 26 and 500, inclusive, will be printed. These will be the numbers of places of the participants who get the Codecraft-17 T-shirts. It is guaranteed that the 25 printed integers will be pairwise distinct for any value of s.

You're in the lead of the elimination round of 8VC Venture Cup 2017, having x points. You believe that having at least y points in the current round will be enough for victory.

To change your final score, you can make any number of successful and unsuccessful hacks. A successful hack brings you 100 points, an unsuccessful one takes 50 points from you. It's difficult to do successful hacks, though.

You want to win the current round and, at the same time, ensure getting a Codecraft-17 T-shirt. What is the smallest number of successful hacks you have to do to achieve that?

Input

The only line contains three integers p, x and y (26 ≤ p ≤ 500; 1 ≤ y ≤ x ≤ 20000) — your place in Codecraft-17, your current score in the elimination round of 8VC Venture Cup 2017, and the smallest number of points you consider sufficient for winning the current round.

Output

Output a single integer — the smallest number of successful hacks you have to do in order to both win the elimination round of 8VC Venture Cup 2017 and ensure getting a Codecraft-17 T-shirt.

It's guaranteed that your goal is achievable for any valid input data.

Examples
Input
239 10880 9889
Output
0
Input
26 7258 6123
Output
2
Input
493 8000 8000
Output
24
Input
101 6800 6500
Output
0
Input
329 19913 19900
Output
8
Note

In the first example, there is no need to do any hacks since 10880 points already bring the T-shirt to the 239-th place of Codecraft-17 (that is, you). In this case, according to the pseudocode, the T-shirts will be given to the participants at the following places:

475 422 84 411 453 210 157 294 146 188 420 367 29 356 398 155 102 239 91 133 365 312 449 301 343

In the second example, you have to do two successful and one unsuccessful hack to make your score equal to 7408.

In the third example, you need to do as many as 24 successful hacks to make your score equal to 10400.

In the fourth example, it's sufficient to do 6 unsuccessful hacks (and no successful ones) to make your score equal to 6500, which is just enough for winning the current round and also getting the T-shirt.

题目链接:http://codeforces.com/contest/807/problem/B

题意:你在另外一场已经结束的比赛中有一个排名p; 然后你现在在进行另外一场比赛 然后你当前有一个分数x; 以及另外一个分数y,表示如果要拿第一需要的分数; 你可以通过hack使得分数x大于分数y; 然后你最后的分数x会决定你那个排名p能不能在已经结束的那场比赛中拿到奖品; 问你技能拿到奖品,又能在这场比赛中夺冠;至少需要hack成功多少次(失败的不需要输出); (hack规则和cf的一样)

分析:如果x< y 则一直给x递增100; 则只要可以保证x>y,就能一直减50分; 然后看看你的分数能不能让你在第p名拿到奖品; 这种情况下,成功hack次数都为0,只是一直是失败的hack; 否则; 然后变回初始的x; 每次考虑hack成功一次以及hack成功和失败各一次的情况; 即+100和+50(这两种情况都是hack成功次数+1能覆盖的情况) 写个暴力就好; 判断分数为x的时候排名为P能不能拿到奖品,可以写个函数!

下面给出AC代码:

 #include<bits/stdc++.h>
using namespace std;
bool check(int s,int p)
{
s=(s/)%;
for(int i=;i<;i++)
{
s=(s*+)%;
if(s+==p)
return ;
}
return ;
}
int main()
{
int x,y,p;
cin>>p>>x>>y;
int z=y+(x-y+)%;
for(int i=z;i<=y+*;i+=)
if(check(i,p))
{
cout<<max(,(i-x+)/)<<endl;
return ;
}
}

C. Success Rate

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.

Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?

Input

The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.

Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).

It is guaranteed that p / q is an irreducible fraction.

Hacks. For hacks, an additional constraint of t ≤ 5 must be met.

Output

For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.

Example
Input
4 
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Output
4 
10
0
-1
Note

In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.

In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.

In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.

In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.

题目链接:http://codeforces.com/contest/807/problem/C

题意:给你4个数字 ,x y p q 要求让你求最小的非负整数b; 使得 (x+a)/(y+b)==p/q ,同时a为一个整数且0<=a<=b !

分析:网上大多数解法用的是二分,没有人用暴力过,那么今天让你们看看传说中的暴力大法吧!

我们知道,因为p要比x大 ,x才能涨上去;y要比q大  ,才能涨上去!又因为x和y只能增加不能减少,而比例 p/q  是可以改变成  p*i/(q*i),因为p/q 已经化简了,所以  p/q 是最小的,通过倍数增上去就会有答案!

下面给出暴力AC解法:

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(ll a,ll b)
{
return b==?a:gcd(b,a%b);
}
ll t,x,y,p,q;
int main()
{
while(scanf("%lld",&t)!=EOF)
{
while(t--)
{
scanf("%lld%lld%lld%lld",&x,&y,&p,&q);
if(p/q==&&x/y==)
printf("-1\n");
else if(p/q==&&x/y==)
printf("0\n");
else if(p==&&x==)
printf("0\n");
else if(p==&&x!=)
printf("-1\n");
else
{
ll k=gcd(p,q);
p/=k;
q/=k;
ll ans=;
ll maxn=(y-x)/(q-p)+((y-x)%(q-p)?:);
maxn=max(maxn,y/q+((y%q)?:));
maxn=max(maxn,x/p+((x%p)?:));
ans=q*maxn-y;
cout<<ans<<endl;
}
}
}
return ;
}

网上的二分解法我也补充一下吧!

(x+a)/(y+b)==p/q;

x+a=np
y+b=nq
(以上结论只在p和q是互质的情况下有效,当然题目有说p和q互质)
a=np-x
b=nq-y
a<=b
因为p<q所以n越大b会越大;
又p和q都大于等于0,所以n越大,a和b都是不下降的
所以二分n

下面给出AC代码:

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std; typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair const ll INF = (ll)3e18; ll solve()
{
ll x, y, p, q;
scanf("%lld%lld%lld%lld", &x, &y, &p, &q);
if (p == q && x < y) return -;
if (p == && x > ) return -;
ll l = , r = INF / q;
while(r - l > )
{
ll d = (l + r) / ;
ll qq = q * d, pp = p * d;
if (y <= qq && x <= pp && pp - x <= qq - y)
r = d;
else
l = d;
}
return q * r - y;
} int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout); int t;
scanf("%d", &t);
while(t--) printf("%lld\n", solve()); return ;
}

Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3)(A.B.C,3道暴力题,C可二分求解)的更多相关文章

  1. Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) A B C D 水 模拟 二分 贪心

    A. Is it rated? time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  2. Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) D - Dynamic Problem Scoring

    地址:http://codeforces.com/contest/807/problem/D 题目: D. Dynamic Problem Scoring time limit per test 2 ...

  3. Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) A Is it rated?

    地址:http://codeforces.com/contest/807/problem/C 题目: C. Success Rate time limit per test 2 seconds mem ...

  4. Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) E. Prairie Partition 二分+贪心

    E. Prairie Partition It can be shown that any positive integer x can be uniquely represented as x =  ...

  5. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!

    Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and ...

  6. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)(A.思维题,B.思维题)

    A. Vicious Keyboard time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  7. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C. Bear and Different Names 贪心

    C. Bear and Different Names 题目连接: http://codeforces.com/contest/791/problem/C Description In the arm ...

  8. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) B - Bear and Friendship Condition 水题

    B. Bear and Friendship Condition 题目连接: http://codeforces.com/contest/791/problem/B Description Bear ...

  9. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) D. Volatile Kite

    地址:http://codeforces.com/contest/801/problem/D 题目: D. Volatile Kite time limit per test 2 seconds me ...

随机推荐

  1. python安装和环境变量的配置

    python安装和环境变量的配置 研究生阶段学习的需求,简单的学习了python的语法和基础之后产生了兴趣,有了想从基础把python学好用好的想法.因此在忙碌的学习中抽出时间,在每天花几个小时学习p ...

  2. mongodb 复制集

    mongodb 复制集 复制集简介 Mongodb复制集由一组Mongod实例(进程)组成,包含一个Primary节点和多个Secondary节点,Mongodb Driver(客户端)的所有数据都写 ...

  3. Java I/O---类体系总结

    1.Java I/O常用 (1)File 对文件系统中文件以及文件夹进行封装的对象,可以通过对象的思想来操作文件和文件夹. (2)FileInputStream 从文件系统中的某个文件中获得输入字节: ...

  4. 框架原理第三讲,RTTCreate,运行时类型创建.(以MFC框架讲解)

    框架原理第三讲,RTTCreate,运行时类型创建.(以MFC框架讲解) 通过昨天的讲解,我们已经理解了运行时类型识别是什么. 比如  CObject * pthis = (Cobject *)Cre ...

  5. tensorflow ckpt文件转caffemodel时遇到的坑

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px ".PingFang SC"; color: #454545 } p.p2 ...

  6. bootstrap 导航栏鼠标悬停显示下拉菜单

    在jsp中加入一下代码: .navbar .nav > li:hover .dropdown-menu { display: block;} 全部代码如下所示: <%@ page lang ...

  7. Elasticsearch5.4常见问题总结

    最近项目中用到了Elasticsearch5.4(ES)是比较新的一个版本,使用的过程中出现了很多的问题,很是头疼,但是问题最终还是解决掉了. 问题一:ESClient获取慢,并且不能获取Client ...

  8. Neo4j学习笔记(2)——数据索引

    和关系数据库一样,Neo4j同样可以创建索引来加快查找速度. 在关系数据库中创建索引需要索引字段和指向记录的指针,通过索引可以快速查找到表中的行. 在Neo4j中,其索引是通过属性来创建,便于快速查找 ...

  9. 如何在MicroPython TPYBoard 添加自定义类库

    开始之前,首先要感谢一下TPYBoard技术交流群(157816561)-云之初晓网友的分享.   今天简单分享下如何将自己编写的一些Python脚本的类库添加到固件中,在使用时只需import调用, ...

  10. HttpRuntime.Cache .Net自带的缓存类

    .Net自带的缓存有两个,一个是Asp.Net的缓存 HttpContext.Cache,一个是.Net应用程序级别的缓存,HttpRuntime.Cache. MSDN上有解释说: HttpCont ...