zoukankan      html  css  js  c++  java
  • Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2) ABC

    A. The Rank

    John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.

    There are nn students, each of them has a unique id (from 11 to nn). Thomas's id is 11. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.

    In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids.

    Please help John find out the rank of his son.

    Input

    The first line contains a single integer nn (1n10001≤n≤1000) — the number of students.

    Each of the next nn lines contains four integers aiai, bibi, cici, and didi (0ai,bi,ci,di1000≤ai,bi,ci,di≤100) — the grades of the ii-th student on English, German, Math, and History. The id of the ii-th student is equal to ii.

    Output

    Print the rank of Thomas Smith. Thomas's id is 11.

    Examples
    input
    Copy
    5
    100 98 100 100
    100 100 100 100
    100 100 99 99
    90 99 90 100
    100 98 60 99
    output
    2
    input
    6
    100 80 90 99
    60 60 60 60
    90 60 100 60
    60 100 60 80
    100 100 0 100
    0 0 0 0
    output
    1
    Note

    In the first sample, the students got total scores: 398398, 400400, 398398, 379379, and 357357. Among the 55 students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is 22.

    In the second sample, the students got total scores: 369369, 240240, 310310, 300300, 300300, and 00. Among the 66 students, Thomas got the highest score, so his rank is 11.

    求第一个人的排名。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int N = 1010;
     4 struct Nod{
     5     int id,s;
     6 }e[N];
     7 int a, n, b, c, d;
     8 bool cmp(const Nod &a, const Nod &b) {
     9     if(a.s != b.s) return a.s > b.s;
    10     else return a.id < b.id;
    11 }
    12 int main() {
    13     cin >> n;
    14     for(int i = 1; i <= n; i ++) {
    15         cin >> a >> b >> c >> d;
    16         e[i].id = i;
    17         e[i].s = a+b+c+d;
    18     }
    19     sort(e+1,e+1+n,cmp);
    20     for(int i = 1; i <= n; i ++) 
    21         if(e[i].id == 1) return 0*printf("%d
    ",i);
    22     return 0;
    23 }

    B. The Bits

    Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:

    Given two binary numbers aa and bb of length nn. How many different ways of swapping two digits in aa (only in aa, not bb) so that bitwise OR of these two numbers will be changed? In other words, let cc be the bitwise OR of aa and bb, you need to find the number of ways of swapping two bits in aa so that bitwise OR will not be equal to cc.

    Note that binary numbers can contain leading zeros so that length of each number is exactly nn.

    Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, 010102010102 OR 100112100112 = 110112110112.

    Well, to your surprise, you are not Rudolf, and you don't need to help him… You are the security staff! Please find the number of ways of swapping two bits in aa so that bitwise OR will be changed.

    Input

    The first line contains one integer nn (2n1052≤n≤105) — the number of bits in each number.

    The second line contains a binary number aa of length nn.

    The third line contains a binary number bb of length nn.

    Output

    Print the number of ways to swap two bits in aa so that bitwise OR will be changed.

    Examples
    input
    Copy
    5
    01011
    11001
    output
    Copy
    4
    input
    Copy
    6
    011000
    010011
    output
    Copy
    6
    Note

    In the first sample, you can swap bits that have indexes (1,4)(1,4), (2,3)(2,3), (3,4)(3,4), and (3,5)(3,5).

    In the second example, you can swap bits that have indexes (1,2)(1,2), (1,3)(1,3), (2,4)(2,4), (3,4)(3,4), (3,5)(3,5), and (3,6)(3,6).

    只能交换a串,那就找b中为0的,因为为1不管怎么交换a串都不会改变原来的值。然后在记录a串中的0、1的数量就行了。

     1 #include <bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 const int N = 2e5+10;
     5 char s1[N], s2[N];
     6 
     7 int main() {
     8     ll x = 0, y = 0, x1 = 0, y1 = 0, n;
     9     cin >> n;
    10     scanf("%s%s",s1,s2);
    11     for(int i = 0; i < n; i ++) {
    12         if(s2[i] == '0' && s1[i] == '0') x++;
    13         else if(s2[i] == '0' && s1[i] == '1') y++;
    14         if(s1[i] == '0') x1++;
    15         else y1++;
    16     }
    17     printf("%lld
    ",x*y1+y*x1-x*y);
    18     return 0;
    19 }

    C. The Phone Number

    Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number!

    The only thing Mrs. Smith remembered was that any permutation of nn can be a secret phone number. Only those permutations that minimize secret value might be the phone of her husband.

    The sequence of nn integers is called a permutation if it contains all integers from 11 to nn exactly once.

    The secret value of a phone number is defined as the sum of the length of the longest increasing subsequence (LIS) and length of the longest decreasing subsequence (LDS).

    A subsequence ai1,ai2,,aikai1,ai2,…,aik where 1i1<i2<<ikn1≤i1<i2<…<ik≤n is called increasing if ai1<ai2<ai3<<aikai1<ai2<ai3<…<aik. If ai1>ai2>ai3>>aikai1>ai2>ai3>…>aik, a subsequence is called decreasing. An increasing/decreasing subsequence is called longest if it has maximum length among all increasing/decreasing subsequences.

    For example, if there is a permutation [6,4,1,7,2,3,5][6,4,1,7,2,3,5], LIS of this permutation will be [1,2,3,5][1,2,3,5], so the length of LIS is equal to 44. LDScan be [6,4,1][6,4,1], [6,4,2][6,4,2], or [6,4,3][6,4,3], so the length of LDS is 33.

    Note, the lengths of LIS and LDS can be different.

    So please help Mrs. Smith to find a permutation that gives a minimum sum of lengths of LIS and LDS.

    Input

    The only line contains one integer nn (1n1051≤n≤105) — the length of permutation that you need to build.

    Output

    Print a permutation that gives a minimum sum of lengths of LIS and LDS.

    If there are multiple answers, print any.

    Examples
    input
    Copy
    4
    output
    Copy
    3 4 1 2
    input
    Copy
    2
    output
    Copy
    2 1
    Note

    In the first sample, you can build a permutation [3,4,1,2][3,4,1,2]. LIS is [3,4][3,4] (or [1,2][1,2]), so the length of LIS is equal to 22. LDS can be ony of [3,1][3,1], [4,2][4,2], [3,2][3,2], or [4,1][4,1]. The length of LDS is also equal to 22. The sum is equal to 44. Note that [3,4,1,2][3,4,1,2] is not the only permutation that is valid.

    In the second sample, you can build a permutation [2,1][2,1]. LIS is [1][1] (or [2][2]), so the length of LIS is equal to 11. LDS is [2,1][2,1], so the length of LDS is equal to 22. The sum is equal to 33. Note that permutation [1,2][1,2] is also valid.

    LIS + LDS. 最小,然后就是求(i+n/i(向上取整))最小的值。

     1 #include <bits/stdc++.h>
     2 #define INF 0x3f3f3f3f
     3 using namespace std;
     4 
     5 int main() {
     6     int n, x, y;
     7     x = y = INF;
     8     cin >> n;
     9     for(int i = 1; i <= sqrt(n); i ++) {
    10         if(i+(n-1)/i+1 < x + y) {
    11             x = i;
    12             y = (n-1)/i+1;
    13         }
    14     }
    15     for(int i = x; i >= 1; i --) {
    16         for(int j = 0; j < y; j ++) {
    17             int ans = (i-1)*y+1+j;
    18             if(1 <= ans && ans <= n)printf("%d ",ans);
    19         }
    20     }
    21     printf("
    ");
    22     return 0;
    23 }
  • 相关阅读:
    一张图片入门Python
    4.1. 如何在Windows环境下开发Python
    你必须知道的EF知识和经验
    XUnit的使用
    如何使用NUnit
    Entity Framework 不支持DefaultValue
    Have You Ever Wondered About the Difference Between NOT NULL and DEFAULT?
    Validation failed for one or more entities. See 'EntityValidationErrors' property for more details
    Entity Framework 与多线程
    sqlite中的自增主键
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/9460794.html
Copyright © 2011-2022 走看看