zoukankan      html  css  js  c++  java
  • ACM Shenyang Onsite 2016 题目

    A. Thickest Burger

    • 1000ms
    • 262144K
     

    ACM ICPC is launching a thick burger. The thickness (or the height) of a piece of club steak is AAA (1≤A≤100)(1 le A le 100)(1A100). The thickness (or the height) of a piece of chicken steak is BBB (1≤B≤100)(1 le B le 100)(1B100).

    The chef allows to add just three pieces of meat into the burger and he does not allow to add three pieces of same type of meat. As a customer and a foodie, you want to know the maximum total thickness of a burger which you can get from the chef. Here we ignore the thickness of breads, vegetables and other seasonings.

    Input

    The first line is the number of test cases. For each test case, a line contains two positive integers AAA and BBB.

    Output

    For each test case, output a line containing the maximum total thickness of a burger.

    Consider the first test case, since 68+68+4268+68+4268+68+42 is bigger than 68+42+4268+42+4268+42+42 the answer should be 68+68+42=17868+68+42 = 17868+68+42=178. Similarly since 1+35+351+35+351+35+35 is bigger than 1+1+351+1+351+1+35, the answer of the second test case should be 1+35+35=711+35+35 = 711+35+35=71.

    样例输入

    10
    68 42
    1 35
    25 70
    59 79
    65 63
    46 6
    28 82
    92 62
    43 96
    37 28

    样例输出

    178
    71
    165
    217
    193
    9
    192
    246
    235
    102

    思路:简单~
    代码:
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 int main()
     5 {
     6     int n;
     7     int a,b;
     8     cin>>n;
     9     while(n--)
    10     {
    11         cin>>a>>b;
    12         int sum=0;
    13         if(a>b)
    14         {
    15             sum=2*a+b;
    16         }
    17         else
    18         {
    19             sum=2*b+a;
    20         }
    21         cout<<sum<<endl;
    22     }
    23     return 0;
    24 }

    B. Relative atomic mass

    • 1000ms
    • 262144K
     

    Relative atomic mass is a dimensionless physical quantity, the ratio of the average mass of atoms of an element (from a single given sample or source) to 112 frac{1}{12}121 of the mass of an atom of carbon-12 (known as the unified atomic mass unit).

    You need to calculate the relative atomic mass of a molecule, which consists of one or several atoms. In this problem, you only need to process molecules which contain hydrogen atoms, oxygen atoms, and carbon atoms. These three types of atom are written as ’HHH’, ’OOO’ and ’CCC’ repectively. For your information, the relative atomic mass of one hydrogen atom is 111, and the relative atomic mass of one oxygen atom is 161616 and the relative atomic mass of one carbon atom is 121212. A molecule is demonstrated as a string, of which each letter is for an atom. For example, a molecule ’HOH’ contains two hydrogen atoms and one oxygen atom, therefore its relative atomic mass is 18=2∗1+1618 = 2 * 1 + 1618=21+16.

    Input

    The first line of input contains one integer N(N≤10)N(N le 10)N(N10), the number of molecules.

    In the next NNN lines, the iii-th line contains a string, describing the iii-th molecule. The length of each string would not exceed 101010.

    Output

    For each molecule, output its relative atomic mass.

    样例输入

    5
    H
    C
    O
    HOH
    CHHHCHHOH

    样例输出

    1
    12
    16
    18
    46
    代码:
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 string s;
     4 int main()
     5 {
     6     int n;
     7     cin>>n;
     8     while(n--)
     9     {
    10         cin>>s;
    11         int len=s.length();
    12         int sum=0;
    13         for(int i=0;i<len;i++)
    14         {
    15             if(s[i]=='H')
    16             {
    17                 sum+=1;
    18             }
    19             else if(s[i]=='C')
    20             {
    21                 sum+=12;
    22             }
    23             else
    24             {
    25                 sum+=16;
    26             }
    27         }
    28         cout<<sum<<endl;
    29 
    30     }
    31     return 0;
    32 }

    C. Recursive sequence

    • 1000ms
    • 262144K
     

    Farmer John likes to play mathematics games with his NNN cows. Recently, they are attracted by recursive sequences. In each turn, the cows would stand in a line, while John writes two positive numbers aaa and bbb on a blackboard. And then, the cows would say their identity number one by one. The first cow says the first number aaa and the second says the second number bbb. After that, the iii-th cow says the sum of twice the (i−2)(i - 2)(i2)-th number, the (i−1)(i - 1)(i1)-th number, and i4i^4i4. Now, you need to write a program to calculate the number of the NNN-th cow in order to check if John’s cows can make it right.

    Input

    The first line of input contains an integer ttt, the number of test cases. ttt test cases follow.

    Each case contains only one line with three numbers NNN, aaa and bbb where N,a,b<231N,a,b < 2^{31}N,a,b<231 as described above.

    Output

    For each test case, output the number of the NNN-th cow. This number might be very large, so you need to output it modulo 214749364721474936472147493647.

    In the first case, the third number is 85=21+2+3485 = 21+2+3^485=21+2+34. In the second case, the third number is 93=21+1∗10+3493 = 21+1*10+3^493=21+110+34 and the fourth number is 369=2∗10+93+44369 = 2 * 10 + 93 + 4^4369=210+93+44.

    样例输入

    2
    3 1 2
    4 1 10

    样例输出

    85
    369
    思路:矩阵快速幂+结构体,写出C*A(N-1)=A(N)。计算:C(N-1)*A(1)=A(N)或者C(N-2)*A(2)=A(N)或者C(N-3)*A(3)=A(N)...
    代码:
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int inf=0x3f3f3f3f;
     4 const long long mod=2147493647;
     5 const int si=10;
     6 typedef long long ll;
     7 
     8 struct mat
     9 {
    10     ll c[si][si];
    11 };
    12 
    13 mat matmul(mat a,mat b)
    14 {
    15     mat ans;
    16     memset(ans.c,0,sizeof ans.c);
    17     for(int i=1; i<=7; i++)
    18     {
    19 
    20         for(int j=1; j<=7; j++)
    21         {
    22             for(int k=1; k<=7; k++)
    23             {
    24                 ans.c[i][j]+=((a.c[i][k]%mod)*(b.c[k][j]%mod))%mod;
    25             }
    26         }
    27     }
    28     return ans;
    29 }
    30 
    31 mat qpow(mat a,ll n)
    32 {
    33     mat ans;
    34     memset(ans.c,0,sizeof ans.c);
    35     for(int i=1; i<=7; i++)
    36     {
    37         ans.c[i][i]=1;
    38     }
    39     while(n)
    40     {
    41         if(n&1)
    42         {
    43             ans=matmul(ans,a);
    44         }
    45         a=matmul(a,a);
    46         n>>=1;
    47     }
    48     return ans;
    49 }
    50 
    51 mat init()
    52 {
    53     mat a;
    54     memset(a.c,0,sizeof a.c);
    55     a.c[1][1]=1,a.c[1][2]=2,a.c[1][3]=1,a.c[1][4]=4,a.c[1][5]=6,a.c[1][6]=4,a.c[1][7]=1;
    56     a.c[2][1]=1,a.c[2][2]=0,a.c[2][3]=0,a.c[2][4]=0,a.c[2][5]=0,a.c[2][6]=0,a.c[2][7]=0;
    57     a.c[3][1]=0,a.c[3][2]=0,a.c[3][3]=1,a.c[3][4]=4,a.c[3][5]=6,a.c[3][6]=4,a.c[3][7]=1;
    58     a.c[4][1]=0,a.c[4][2]=0,a.c[4][3]=0,a.c[4][4]=1,a.c[4][5]=3,a.c[4][6]=3,a.c[4][7]=1;
    59     a.c[5][1]=0,a.c[5][2]=0,a.c[5][3]=0,a.c[5][4]=0,a.c[5][5]=1,a.c[5][6]=2,a.c[5][7]=1;
    60     a.c[6][1]=0,a.c[6][2]=0,a.c[6][3]=0,a.c[6][4]=0,a.c[6][5]=0,a.c[6][6]=1,a.c[6][7]=1;
    61     a.c[7][1]=0,a.c[7][2]=0,a.c[7][3]=0,a.c[7][4]=0,a.c[7][5]=0,a.c[7][6]=0,a.c[7][7]=1;
    62     return a;
    63 
    64 }
    65 
    66 int main()
    67 {
    68     ll n,t,q,w;
    69     cin>>t;
    70     while(t--)
    71     {
    72         cin>>n>>q>>w;
    73         mat b;
    74         b.c[1][1]=w,b.c[2][1]=q,b.c[3][1]=16,b.c[4][1]=8,b.c[5][1]=4,b.c[6][1]=2,b.c[7][1]=1;
    75         mat res;
    76         res=qpow(init(),n-2);
    77         res=matmul(res,b);
    78         printf("%lld
    ",(res.c[1][1])%mod);
    79     }
    80     return 0;
    81 }
  • 相关阅读:
    过滤指定目录下指定后缀名文件
    Oracle 存储过程创建表
    编码测试之控制条件筛选心得——AE二次开发篇
    log4j配置祥解 (转)
    手机浏览器的viewport(视觉窗口)
    git 常用技巧
    添加eclipse的字体样式
    如何检测android 文件签名成功(转帖)
    javascript 解析json
    身份证正则表达式
  • 原文地址:https://www.cnblogs.com/weixq351/p/9745242.html
Copyright © 2011-2022 走看看