zoukankan      html  css  js  c++  java
  • 140

     

    Ace of Aces


    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    There is a mysterious organization called Time-Space Administrative Bureau (TSAB) in the deep universe that we humans have not discovered yet. This year, the TSAB decided to elect an outstanding member from its elite troops. The elected guy will be honored with the title of "Ace of Aces".

    After voting, the TSAB received N valid tickets. On each ticket, there is a number Ai denoting the ID of a candidate. The candidate with the most tickets nominated will be elected as the "Ace of Aces". If there are two or more candidates have the same number of nominations, no one will win.

    Please write program to help TSAB determine who will be the "Ace of Aces".

    Input

    There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

    The first line contains an integer N (1 <= N <= 1000). The next line contains N integers Ai (1 <= Ai <= 1000).

    Output

    For each test case, output the ID of the candidate who will be honored with "Ace of Aces". If no one win the election, output "Nobody" (without quotes) instead.

    Sample Input

    3
    5
    2 2 2 1 1
    5
    1 1 2 2 3
    1
    998
    

    Sample Output

    2
    Nobody
    998
    

     

    题意:求出现次数最多的那个数,如果有多个(最多次数相等的)就输出Nobody

    转载请注明出处:寻找&星空の孩子

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <stack>
     5 #include <queue>
     6 #include <map>
     7 #include <set>
     8 #include <vector>
     9 #include <math.h>
    10 #include <algorithm>
    11 using namespace std;
    12 #define ls 2*i
    13 #define rs 2*i+1
    14 #define up(i,x,y) for(i=x;i<=y;i++)
    15 #define down(i,x,y) for(i=x;i>=y;i--)
    16 #define mem(a,x) memset(a,x,sizeof(a))
    17 #define w(a) while(a)
    18 #define LL long long
    19 const double pi = acos(-1.0);
    20 #define Len 20005
    21 #define mod 19999997
    22 const int INF = 0x3f3f3f3f;
    23 
    24 int t,n,a,maxn,flag;
    25 
    26 struct node
    27 {
    28     int cnt,id;
    29 }hsh[1005];
    30 
    31 int cmp(node a,node b)
    32 {
    33     return a.cnt<b.cnt;
    34 };
    35 
    36 int main()
    37 {
    38     int i;
    39     scanf("%d",&t);
    40     w(t--)
    41     {
    42         scanf("%d",&n);
    43         mem(hsh,0);
    44         up(i,0,n-1)
    45         {
    46             scanf("%d",&a);
    47             hsh[a].id = a;
    48             hsh[a].cnt++;
    49         }
    50         sort(hsh,hsh+1001,cmp);
    51         if(hsh[1000].cnt==hsh[999].cnt)
    52             printf("Nobody
    ");
    53         else
    54             printf("%d
    ",hsh[1000].id);
    55     }
    56 
    57     return 0;
    58 }
    View Code
    
    
    

    Team Formation


    Time Limit: 3 Seconds      Memory Limit: 131072 KB

    For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-man team from N students of his university.

    Edward knows the skill level of each student. He has found that if two students with skill level A and B form a team, the skill level of the team will be A ⊕ B, where ⊕ means bitwise exclusive or. A team will play well if and only if the skill level of the team is greater than the skill level of each team member (i.e. A ⊕ B > max{AB}).

    Edward wants to form a team that will play well in the contest. Please tell him the possible number of such teams. Two teams are considered different if there is at least one different team member.

    Input

    There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

    The first line contains an integer N (2 <= N <= 100000), which indicates the number of student. The next line contains N positive integers separated by spaces. The ith integer denotes the skill level of ith student. Every integer will not exceed 109.

    Output

    For each case, print the answer in one line.

    Sample Input

    2
    3
    1 2 3
    5
    1 2 3 4 5
    

    Sample Output

    1
    6

    题意:选数组里的两个数,要求A与B异或得C,C>max(A,B);

     

    思路:利用二进制,把每个数分解成二进制,循环对每个数的各个位取&,在高位相等的情况下,低位有为0的情况就说明可以加上,然后加上对应是数量。

     转载请注明出处:寻找&星空の孩子

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <stack>
     5 #include <queue>
     6 #include <map>
     7 #include <set>
     8 #include <vector>
     9 #include <math.h>
    10 #include <algorithm>
    11 using namespace std;
    12 #define ls 2*i
    13 #define rs 2*i+1
    14 #define up(i,x,y) for(i=x;i<=y;i++)
    15 #define down(i,x,y) for(i=x;i>=y;i--)
    16 #define mem(a,x) memset(a,x,sizeof(a))
    17 #define w(a) while(a)
    18 #define LL long long
    19 const double pi = acos(-1.0);
    20 #define Len 20005
    21 #define mod 19999997
    22 const int INF = 0x3f3f3f3f;
    23 
    24 int t,n,a[100005],bit[100];
    25 
    26 int main()
    27 {
    28     int i,j,k;
    29     scanf("%d",&t);
    30     w(t--)
    31     {
    32         mem(bit,0);
    33         scanf("%d",&n);
    34         up(i,0,n-1)
    35         {
    36             scanf("%d",&a[i]);
    37             for(j = 31;j>=0;j--)
    38             {
    39                 if(a[i]&(1<<j))
    40                 {
    41                     bit[j]++;
    42                     break;
    43                 }
    44             }
    45         }
    46         LL ans = 0;
    47         up(i,0,n-1)
    48         {
    49             if(a[i])
    50             {
    51                 int l = 31;
    52                 w(1)
    53                 {
    54                     if(a[i]&(1<<l)) break;
    55                     l--;
    56                 }
    57                 w(l>=0)
    58                 {
    59                     if(!(a[i]&(1<<l))) ans+=bit[l];
    60                     l--;
    61                 }
    62             }
    63         }
    64         printf("%lld
    ",ans);
    65     }
    66 
    67     return 0;
    68 }
    View Code
    
    
    

    Convex Hull


    Time Limit: 3 Seconds      Memory Limit: 65536 KB

    Edward has n points on the plane. He picks a subset of points (at least three points), and defines the beauty of the subset as twice the area of corresponding convex hull. Edward wants to know summation of the beauty of all possible subsets of points (at least three points).

    No two points coincide and no three points are on the same line.

    Input

    There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

    The first line contains an integer n (3 ≤ n ≤ 1000). Each of following n lines contains 2 integers xiyi which denotes a point (xiyi) (0 ≤ |xi|, |yi| ≤ 109).

    The sum of values n for all the test cases does not exceed 5000.

    Output

    For each case, if the answer is S, output a single integer denotes S modulo 998244353.

    Sample Input

    1
    3
    0 0
    0 1
    1 0
    

    Sample Output

    1
    
    

    题意:求凸边型面积的2倍,问你取大于等于3个点的两倍面积的和;

    思路:求每个三个点组成的三角形面积的2倍,然后多边形面积可以由三角形面积的加起来;(三角形每个有2^(n-3)个)

    (超时了。。。还在改,有没有更好的思路)

    Beauty of Array


    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous subarray of the array A.

    Input

    There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

    The first line contains an integer N (1 <= N <= 100000), which indicates the size of the array. The next line contains N positive integers separated by spaces. Every integer is no larger than 1000000.

    Output

    For each case, print the answer in one line.

    Sample Input

    3
    5
    1 2 3 4 5
    3
    2 3 3
    4
    2 3 3 2
    

    Sample Output

    105
    21
    38

     转载请注明出处:寻找&星空の孩子

    题意:算连续集合里不同数的和,然后所有集合的总和;

    思路:dp,每次新加的数,先dp[i-1]+a[i],总是要减去最近的相同的数的个数;

    eg:         2                   3                         4                       3                          2                           3 .....(括号内的数,表示集合由多少个数)

                 2(1)                3(1)                      4(1)                  3(1)                      2(1)                       3(1)

                                   2+3(2)                  3+4(2)               4+3(2)                 3+2(2)                   2+3(2)

                                                           2+3+4(3)               3+4(3)             4+3+2(3)                   3+2(3)

                                                                                    2+3+4(4)             3+4+2(4)               4+3+2(4)

                                                                                                               2+3+4(5)               3+4+2(5)    

                                                                                                                                            2+3+4(5)

     1 #include<stdio.h>
     2 #include<string.h>
     3 #define LL long long
     4 const int N = 1000005;
     5 LL dp[N];
     6 int hsh[N];
     7 
     8 int main()
     9 {
    10     int t,n,a;
    11     scanf("%d",&t);
    12     while(t--)
    13     {
    14         memset(hsh,0,sizeof(hsh));
    15         scanf("%d",&n);
    16         dp[0]=0;
    17         for(int i=1;i<=n;i++)
    18         {
    19             scanf("%d",&a);
    20             dp[i]=dp[i-1]+a+(i-1-hsh[a])*a;
    21             hsh[a]=i;
    22         }
    23         LL ans=0;
    24         for(int i=1;i<=n;i++)
    25             ans+=dp[i];
    26         printf("%lld
    ",ans);
    27     }
    28 }
    View Code
  • 相关阅读:
    个人博客
    个人博客
    个人博客
    个人博客
    个人博客
    个人博客
    个人博客
    5.14
    5.13
    5.12
  • 原文地址:https://www.cnblogs.com/yuyixingkong/p/4456561.html
Copyright © 2011-2022 走看看