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)(1≤A≤100). The thickness (or the height) of a piece of chicken steak is BBB (1≤B≤100)(1 \le B \le 100)(1≤B≤100).

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\tfrac{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=2∗1+16.

Input

The first line of input contains one integer N(N≤10)N(N \le 10)N(N≤10), 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)(i−2)-th number, the (i−1)(i - 1)(i−1)-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+1∗10+34 and the fourth number is 369=2∗10+93+44369 = 2 * 10 + 93 + 4^4369=2∗10+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)...
代码:
 #include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
const long long mod=;
const int si=;
typedef long long ll; struct mat
{
ll c[si][si];
}; mat matmul(mat a,mat b)
{
mat ans;
memset(ans.c,,sizeof ans.c);
for(int i=; i<=; i++)
{ for(int j=; j<=; j++)
{
for(int k=; k<=; k++)
{
ans.c[i][j]+=((a.c[i][k]%mod)*(b.c[k][j]%mod))%mod;
}
}
}
return ans;
} mat qpow(mat a,ll n)
{
mat ans;
memset(ans.c,,sizeof ans.c);
for(int i=; i<=; i++)
{
ans.c[i][i]=;
}
while(n)
{
if(n&)
{
ans=matmul(ans,a);
}
a=matmul(a,a);
n>>=;
}
return ans;
} mat init()
{
mat a;
memset(a.c,,sizeof a.c);
a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=;
a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=;
a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=;
a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=;
a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=;
a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=;
a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=,a.c[][]=;
return a; } int main()
{
ll n,t,q,w;
cin>>t;
while(t--)
{
cin>>n>>q>>w;
mat b;
b.c[][]=w,b.c[][]=q,b.c[][]=,b.c[][]=,b.c[][]=,b.c[][]=,b.c[][]=;
mat res;
res=qpow(init(),n-);
res=matmul(res,b);
printf("%lld\n",(res.c[][])%mod);
}
return ;
}

ACM Shenyang Onsite 2016 题目的更多相关文章

  1. ACM - 概率、期望题目 小结(临时)

    概率DP求期望大多数都是全期望公式的运用.主要思考状态空间的划分以及状态事件发生的概率.问题可以分为无环和有环两类.无环一类多数比较简单,可以通过迭代或者记忆化搜索完成.有环一类略复杂,可以通过假设方 ...

  2. 2019浙江ACM省赛——部分题目

    有一些题目过了我还没有重新写,先放一些我重新写好了的吧 签到题拿到了信心吧,9分钟写完两题,我们贼开心,我大哥说签到题有什么好开心的,如果不是我有一些地方卡了下,可能还是更快吧,还有就是测试案例多试了 ...

  3. 【赛后补题】(HDU6223) Infinite Fraction Path {2017-ACM/ICPC Shenyang Onsite}

    场上第二条卡我队的题目. 题意与分析 按照题意能够生成一个有环的n个点图(每个点有个位数的权值).图上路过n个点显然能够生成一个n位数的序列.求一个最大序列. 这条题目显然是搜索,但是我队在场上(我负 ...

  4. 【赛后补题】(HDU6228) Tree {2017-ACM/ICPC Shenyang Onsite}

    这条题目当时卡了我们半天,于是成功打铁--今天回来一看,mmp,贪心思想怎么这么弱智.....(怪不得场上那么多人A了 题意分析 这里是原题: Tree Time Limit: 2000/1000 M ...

  5. ACM学习历程—2016"百度之星" - 资格赛(Astar Round1)

    http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=690 A题: 给定字符串,求任意区间的Hash值. 根据题目给定的Hash方式,属 ...

  6. ACM 暴力搜索题 题目整理

    UVa 129 Krypton Factor 注意输出格式,比较坑爹. 每次要进行处理去掉容易的串,统计困难串的个数. #include<iostream> #include<vec ...

  7. ACM题目推荐(刘汝佳书上出现的一些题目)[非原创]

    原地址:http://blog.csdn.net/hncqp/article/details/1758337 推荐一些题目,希望对参与ICPC竞赛的同学有所帮助. POJ上一些题目在http://16 ...

  8. ACM计算几何题目推荐

    //第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...

  9. 山东省第四届acm解题报告(部分)

    Rescue The PrincessCrawling in process... Crawling failed   Description Several days ago, a beast ca ...

随机推荐

  1. 为什么企业依赖于 NoSQL

    如果你关注大数据科技动向,你对 NoSQL 一定不陌生,NoSQL 是一个分布式数据库.在过去时间,数据存储一直关系型数据库天下,有着良好的控制并发操作.事务功能.虽然RDBMS很优秀,但是随着时间的 ...

  2. 为eclipse添加源代码

    看到这个页面,直接点击 红色区域 attach source 关联源代码,进入到如下页面: 点击第二个选择外部的路径,点击导入文件夹,也就是解压出来的src文件夹(不建议直接导整个jar包,虽然也可以 ...

  3. 2017-2018-1 20155320 第五周 加分题-mybash的实现

    2017-2018-1 20155320 第五周 加分题-mybash的实现 使用fork,exec,wait实现mybash 写出伪代码,产品代码和测试代码 发表知识理解,实现过程和问题解决的博客( ...

  4. [UOJ266]Alice和Bob又在玩游戏

    [UOJ266]Alice和Bob又在玩游戏 Tags:题解 作业部落 评论地址 TAG:博弈 题意 不同于树的删边游戏,删掉一个点删去的是到根的路径 题解 这题只和计算\(SG\)有关,博弈的有关内 ...

  5. 洛谷 P1350 车的放置

    洛谷 P1350 车的放置 题目描述 有下面这样的一个网格棋盘,a,b,c,d表示了对应边长度,也就是对应格子数. 当a=b=c=d=2时,对应下面这样一个棋盘 要在这个棋盘上放K个相互不攻击的车,也 ...

  6. python安装mysql

    一.MySQL是一种关系数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性. 二.最近在学习python语言,总体上面来说还是接触的挺快 ...

  7. P1903 [国家集训队]数颜色 带修改莫队板子

    大概就是要多加一维time 然后按照(l的块,r的块,time)为关键字排序 转移区间修改还是按照莫队的方式(每个修改要记修改前后的状态) 然后玄学dalao告诉窝块大小设为\(O(n^{\frac{ ...

  8. python中偏函数的应用

    一.什么是偏函数? (1)在Python的functools模块众多的功能中,其中有一个就是偏函数,我们称之为 partial function 模块的概念我们下一篇在细讲. (2)我们都听过偏将军吧 ...

  9. ASP.NET MVC - PageData的应用

    一.要实现一个功能,在不同的页面放置一段如下的内容,用于采集用户行为信息: <input type='hidden' id='page_id' value='xxxx' /> <sc ...

  10. variadic templates & pass by const reference & member operator [] in const map & gcc sucks

    /// bugs code with comments #include <iostream> #include <memory> #include <unordered ...