A. Is it rated?
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.
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.
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".
6
3060 3060
2194 2194
2876 2903
2624 2624
3007 2991
2884 2884
rated
4
1500 1500
1300 1300
1200 1200
1400 1400
unrated
5
3123 3123
2777 2777
2246 2246
2246 2246
1699 1699
maybe
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
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?
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 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.
239 10880 9889
0
26 7258 6123
2
493 8000 8000
24
101 6800 6500
0
329 19913 19900
8
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
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?
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.
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.
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
4
10
0
-1
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 ;
}