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. Python3 将txt数据转换成列表,进行排序,筛选

    Python 程序员需要知道的 30 个技巧 首先是数据: 将上边的四个数据分别写在新建的txt文件中 1.将txt数据转为列表 with open('james.txt') as jaf: data ...

  2. Python Xcode搭建Python环境以及使用PyCharm CE

    pycharm CE下载   使用教程 1.基础学习网站 2.在Xcode7中搭建python开发环境,这个不行了就试试第二个,我是第二个可以正常输出了,第一个没有输出 3.Python学习-MAC下 ...

  3. bzoj 4444: [Scoi2015]国旗计划

    Description A国正在开展一项伟大的计划--国旗计划.这项计划的内容是边防战士手举国旗环绕边境线奔袭一圈.这 项计划需要多名边防战士以接力的形式共同完成,为此,国土安全局已经挑选了N名优秀的 ...

  4. calling c++ from golang with swig--windows dll (四)

    calling c++ from golang with swig--windows dll 四 前面讲述了windows环境下golang如何通过swig调用C++ dll.由于编译c++代码使用了 ...

  5. js 停止事件冒泡 阻止浏览器的默认行为(阻止a标签跳转 )

    在前端开发工作中,由于浏览器兼容性等问题,我们会经常用到"停止事件冒泡"和"阻止浏览器默认行为". 1..停止事件冒泡 JavaScript代码 //如果提供了 ...

  6. mybatis的知识点

    mybatis核心配置文件的配置 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE conf ...

  7. thinkinginjava学习笔记06_复用类

    MarsEdit粘代码好麻烦,所有代码交给github:https://github.com/lozybean/MyJavaLearning 复用一个类常用的两种方式:组合.继承: 组合 将对象引用置 ...

  8. ubuntu更换阿里源

    网上应该可以找到很多关于ubuntu源的设置方法,但是如果不搞清楚就随便设置的话,不仅不能起到应有的效果,还会由于一些问题导致apt不可用. 最正确的更换源的方法应该如系统提示的: ## a.) ad ...

  9. 【JDK1.8】JDK1.8集合源码阅读——LinkedList

    一.前言 这次我们来看一下常见的List中的第二个--LinkedList,在前面分析ArrayList的时候,我们提到,LinkedList是链表的结构,其实它跟我们在分析map的时候讲到的Link ...

  10. 02-01官网静默模式安装WebLogic

    参考连接:https://docs.oracle.com/middleware/11119/wls/WLSIG/silent.htm#CIHCAHGC 以静默模式运行安装程序 本章介绍如何以静默方式运 ...