• Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3)(A.B.C,3道暴力题,C可二分求解)


    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代码:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int a[1010],b[1010];
     4 int main()
     5 {
     6     int n;
     7     while(scanf("%d",&n)!=EOF)
     8     {
     9         int sum=0;
    10         for(int i=1;i<=n;i++)
    11         {
    12             scanf("%d%d",&a[i],&b[i]);
    13             if(a[i]==b[i])
    14                 sum++;
    15         }
    16         if(sum!=n)
    17             printf("rated
    ");
    18         else
    19         {
    20             int ans=0;
    21             for(int i=1;i<=n;i++)
    22             {
    23                 if(a[i]>=a[i+1])
    24                     ans++;
    25             }
    26             if(ans==n)
    27                 printf("maybe
    ");
    28             else printf("unrated
    ");
    29         }
    30     }
    31     return 0;
    32 }

    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代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 bool check(int s,int p)
     4 {
     5     s=(s/50)%475;
     6     for(int i=0;i<25;i++)
     7     {
     8         s=(s*96+42)%475;
     9         if(s+26==p)
    10             return 1;
    11     }
    12     return 0;
    13 }
    14 int main()
    15 {
    16     int x,y,p;
    17     cin>>p>>x>>y;
    18     int z=y+(x-y+10000)%50;
    19     for(int i=z;i<=y+475*100;i+=50)
    20     if(check(i,p))
    21     {
    22         cout<<max(0,(i-x+50)/100)<<endl;
    23         return 0;
    24     }
    25 }

    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解法:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 int gcd(ll a,ll b)
     5 {
     6     return b==0?a:gcd(b,a%b);
     7 }
     8 ll t,x,y,p,q;
     9 int main()
    10 {
    11     while(scanf("%lld",&t)!=EOF)
    12     {
    13         while(t--)
    14         {
    15             scanf("%lld%lld%lld%lld",&x,&y,&p,&q);
    16             if(p/q==1&&x/y==0)
    17                 printf("-1
    ");
    18             else if(p/q==1&&x/y==1)
    19                 printf("0
    ");
    20             else if(p==0&&x==0)
    21                 printf("0
    ");
    22             else if(p==0&&x!=0)
    23                 printf("-1
    ");
    24             else
    25             {
    26                 ll k=gcd(p,q);
    27                 p/=k;
    28                 q/=k;
    29                 ll ans=0;
    30                 ll maxn=(y-x)/(q-p)+((y-x)%(q-p)?1:0);
    31                 maxn=max(maxn,y/q+((y%q)?1:0));
    32                 maxn=max(maxn,x/p+((x%p)?1:0));
    33                 ans=q*maxn-y;
    34                 cout<<ans<<endl;
    35             }
    36         }
    37     }
    38     return 0;
    39 }

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

    (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代码:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <algorithm>
     5 #include <vector>
     6 #include <set>
     7 #include <map>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <string>
    11 #include <cstring>
    12 #include <complex>
    13 using namespace std;
    14 
    15 typedef long long ll;
    16 typedef pair<int, int> pii;
    17 #define mp make_pair
    18 
    19 const ll INF = (ll)3e18;
    20 
    21 ll solve()
    22 {
    23     ll x, y, p, q;
    24     scanf("%lld%lld%lld%lld", &x, &y, &p, &q);
    25     if (p == q && x < y) return -1;
    26     if (p == 0 && x > 0) return -1;
    27     ll l = 0, r = INF / q;
    28     while(r - l > 1)
    29     {
    30         ll d = (l + r) / 2;
    31         ll qq = q * d, pp = p * d;
    32         if (y <= qq && x <= pp && pp - x <= qq - y)
    33             r = d;
    34         else
    35             l = d;
    36     }
    37     return q * r - y;
    38 }
    39 
    40 int main()
    41 {
    42 //    freopen("input.txt", "r", stdin);
    43 //    freopen("output.txt", "w", stdout);
    44 
    45     int t;
    46     scanf("%d", &t);
    47     while(t--) printf("%lld
    ", solve());
    48 
    49     return 0;
    50 }

      

                   
           

               

  • 相关阅读:
    iptables作为路由转发至后端web服务器
    AWS EC磁盘扩容针对XFS
    MongoDB集群分片部署
    理解Java对象:要从内存布局及底层机制说起,话说….
    类和对象在JVM中是如何存储的,竟然有一半人回答不上来!
    SpringBoot项目中,如何更规范的使用PageHelper分页?
    面试被问,一千万个整数里面快速查找某个整数,你会怎么去做?
    Spock单元测试框架实战指南三-If esle 多分支场景测试
    IDEA激活码,2021年最新IDEA永久激活码无偿分享!
    MQ消息队列(应用场景,产品对比)
  • 原文地址:https://www.cnblogs.com/ECJTUACM-873284962/p/6827005.html
Copyright © 2020-2023  润新知