• Chip Factory ---- UVALive


    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5204

    John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage large amounts of products, every processor has a serial number. More specifically, the factory produces n chips today, the i-th chip produced this day has a serial number si .

    At the end of the day, he packages all the chips produced this day, and send it to wholesalers. More specially, he writes a checksum number on the package, this checksum is defined as below:

    which i, j, k are three different integers between 1 and n. And ⊕ is symbol of bitwise XOR.

    Can you help John calculate the checksum number of today?

    Input

    The first line of input contains an integer T indicating the total number of test cases.

    The first line of each test case is an integer n, indicating the number of chips produced today. The next line has n integers s1, s2, . . . , sn, separated with single space, indicating serial number of each chip.

    • 1 ≤ T ≤ 1000

    • 3 ≤ n ≤ 1000

    • 0 ≤ si ≤ 109

    • There are at most 10 testcases with n > 100

    Output

    For each test case, please output an integer indicating the checksum number in a line.

    Sample Input

    2

    3

    1 2 3

    3

    100 200 300

    Sample Output

    6

    400

    这道题没啥好说的,训练赛的时候脑子抽抽了觉的以下代码会T掉,就想别的招去了,WA到怀疑人生QWQ

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 #include <ctime>
     5 #include <climits>
     6 #include <string>
     7 #include <cstring>
     8 using namespace std;
     9 typedef long long ll;
    10 
    11 
    12 int main()
    13 {
    14     ios::sync_with_stdio(false);
    15     int T, n;
    16     ll a[1010];
    17     ll maxn;
    18     cin>>T;
    19     while( T-- )
    20     {
    21 
    22         maxn = 0;
    23         cin>>n;
    24         for(int i=0; i<n; i++ )
    25         {
    26             cin>>a[i];
    27         }
    28 
    29         for(int i=0; i<n; i++ )
    30         {
    31             for(int j=i+1; j<n; j++ )
    32             {
    33                 for(int k=0; k<n; k++ )
    34                 {
    35                     if( i!=j && i!=k && j!=k )
    36                     {
    37                         if( ((a[i]+a[j])^a[k]) > maxn )
    38                             maxn = (a[i]+a[j])^a[k];
    39                     }
    40                 }
    41             }
    42         }
    43         cout<<maxn<<endl;
    44     }
    45     return 0;
    46 }

    再快一点的:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 #include <ctime>
     5 #include <climits>
     6 #include <string>
     7 #include <cstring>
     8 using namespace std;
     9 typedef long long ll;
    10 
    11 
    12 int main()
    13 {
    14     ios::sync_with_stdio(false);
    15     int T, n;
    16     ll a[1010];
    17     ll maxn;
    18     cin>>T;
    19     while( T-- )
    20     {
    21 
    22         maxn = 0;
    23         cin>>n;
    24         for(int i=0; i<n; i++ )
    25         {
    26             cin>>a[i];
    27         }
    28 
    29         for(int i=0; i<n; i++ )
    30         {
    31             for(int j=i+1; j<n; j++ )
    32             {
    33                 for(int k=j + 1; k<n; k++ )
    34                 {
    35                     maxn = max((a[i]+a[j])^a[k], maxn);
    36                     maxn = max((a[i]+a[k])^a[j], maxn);
    37                     maxn = max((a[j]+a[k])^a[i], maxn);
    38                 }
    39             }
    40         }
    41         cout<<maxn<<endl;
    42     }
    43     return 0;
    44 }
  • 相关阅读:
    UML类图图示样例
    在WSSv3中通过Javascript和创建Feature扩展站点的动作菜单
    LINQ之Select各种操作
    TroubleShoot: SharePoint工作流不能自动启动
    TroubleShoot:页面上WebPart显示错误
    ECMAScript对列表项的增删改查
    隐藏SharePoint查看所有内容及回收站
    Windows2000计划任务对机器进行重新启动
    CF576E Painting Edges
    CF1491H Yuezheng Ling and Dynamic Tree
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11502612.html
Copyright © 2020-2023  润新知