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)(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 题目的更多相关文章
- ACM - 概率、期望题目 小结(临时)
概率DP求期望大多数都是全期望公式的运用.主要思考状态空间的划分以及状态事件发生的概率.问题可以分为无环和有环两类.无环一类多数比较简单,可以通过迭代或者记忆化搜索完成.有环一类略复杂,可以通过假设方 ...
- 2019浙江ACM省赛——部分题目
有一些题目过了我还没有重新写,先放一些我重新写好了的吧 签到题拿到了信心吧,9分钟写完两题,我们贼开心,我大哥说签到题有什么好开心的,如果不是我有一些地方卡了下,可能还是更快吧,还有就是测试案例多试了 ...
- 【赛后补题】(HDU6223) Infinite Fraction Path {2017-ACM/ICPC Shenyang Onsite}
场上第二条卡我队的题目. 题意与分析 按照题意能够生成一个有环的n个点图(每个点有个位数的权值).图上路过n个点显然能够生成一个n位数的序列.求一个最大序列. 这条题目显然是搜索,但是我队在场上(我负 ...
- 【赛后补题】(HDU6228) Tree {2017-ACM/ICPC Shenyang Onsite}
这条题目当时卡了我们半天,于是成功打铁--今天回来一看,mmp,贪心思想怎么这么弱智.....(怪不得场上那么多人A了 题意分析 这里是原题: Tree Time Limit: 2000/1000 M ...
- ACM学习历程—2016"百度之星" - 资格赛(Astar Round1)
http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=690 A题: 给定字符串,求任意区间的Hash值. 根据题目给定的Hash方式,属 ...
- ACM 暴力搜索题 题目整理
UVa 129 Krypton Factor 注意输出格式,比较坑爹. 每次要进行处理去掉容易的串,统计困难串的个数. #include<iostream> #include<vec ...
- ACM题目推荐(刘汝佳书上出现的一些题目)[非原创]
原地址:http://blog.csdn.net/hncqp/article/details/1758337 推荐一些题目,希望对参与ICPC竞赛的同学有所帮助. POJ上一些题目在http://16 ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
- 山东省第四届acm解题报告(部分)
Rescue The PrincessCrawling in process... Crawling failed Description Several days ago, a beast ca ...
随机推荐
- 一个yum源for centos6.x
rpm -Uvh http://www.city-fan.org/ftp/contrib/yum-repo/city-fan.org-release-1-12.rhel6.noarch.rpm
- STM32通用定时器配置
一.STM32通用定时器原理 STM32 系列的CPU,有多达8个定时器,其中TIM1和TIM8是能够产生三对PWM互补输出的高级定时器,常用于三相电机的驱动,它们的时钟由APB2的输出产生.其它6个 ...
- 【转载】COM 组件设计与应用(九)——IDispatch 接口 for VC6.0
原文: http://vckbase.com/index.php/wv/1224.html 一.前言 终于写到了第九回,我也一直期盼着写这回的内容耶,为啥呢?因为自动化(automation)是非常常 ...
- Codeforces 937 D. Sleepy Game(DFS 判断环)
题目链接: Sleepy Game 题意: Petya and Vasya 在玩移动旗子的游戏, 谁不能移动就输了. Vasya在订移动计划的时候睡着了, 然后Petya 就想趁着Vasya睡着的时候 ...
- javaweb学习3——验证码
声明:本文只是自学过程中,记录自己不会的知识点的摘要,如果想详细学习JavaWeb,请到孤傲苍狼博客学习,JavaWeb学习点此跳转 本文链接:https://www.cnblogs.com/xdp- ...
- Linux中的mysql指令
如何启动/停止/重启MySQL一.启动方式1.使用 service 启动:service mysqld start2.使用 mysqld 脚本启动:/etc/inint.d/mysqld start3 ...
- excel 取前几位文字
1L.2L的分别用mid函数和left函数都没有问题. 问题是,如果用left函数,必须先确认,字符串中汉字必须排在左边第一个,接下来几个也必须是汉字:mid函数则是根据从左边第某个字符开始,一共取几 ...
- Error! Failed to install react, react-dom, next, try again.
问题:用create-next-app创建应用报错,部分模块没有安装,react.react-dom.next等模块安装失败,如下图所示 操作环境: 系统:Ubuntu 16.04.4 LTS npm ...
- [硬件配置]Ubuntu 16.04下使用NETGEAR Nighthawk AC1900 (A7000) WIFi USB适配器
为了增强无人机与地面站之间的传输信号,组里买了这款WiFi信号接收器,无奈只有Windows和Mac OS版本的驱动程序.后来不知道从哪里得来的一个偏方可以安装Ubuntu下的驱动,特此记录. 内核降 ...
- Netty源码分析第1章(Netty启动流程)---->第3节: 服务端channel初始化
Netty源码分析第一章:Netty启动流程 第三节:服务端channel初始化 回顾上一小节的initAndRegister()方法: final ChannelFuture initAndRe ...