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 ...
随机推荐
- 针对Windows 64位系统中Matlab没有LED Control Activex控件的解决方法
Win 10 64bits系统中Matlab 64位软件没有LED Control Activex控件,LED ActiveX Control控件位于Gauges Blockset模块中,而Gauge ...
- dos下edit编辑器的快捷命令一览
Home Move cursor to the beginning of the line currently on. End Move cursor to the end of the line c ...
- AGC 015 E - Mr.Aoki Incubator
E - Mr.Aoki Incubator 链接 题意: 数轴上有N个黑点,每个点都有一个方向向右的正速度v.当两个点在同一个位置上重合时,若其中一个是红色,另一个也变成红色.保证没有相同速度或初始坐 ...
- Spring boot jpa @Column命名大小写问题
一.问题 驼峰命名会被自动转成数据库下划线命名,指定@Column的name也不起作用 举例: @Column(nullable = false,name = "resolvedDate&q ...
- SSIS 控制流和数据流
在SSIS的体系结构中,Package是SSIS的最重要的部分,从本质上来讲,Package是一个有序地执行任务的单元.Package的核心是控制流(Control Flow),用于协调包中所有组件的 ...
- SSIS 数据流的执行树和数据管道
数据流组件的设计愿景是快速处理海量的数据,为了实现该目标,SSIS数据源引擎需要创建执行树和数据管道这两个数据结构,而用户为了快速处理数据流,必须知道各个转换组件的阻塞性,充分利用流式处理流程,利用更 ...
- Textarea的readonly问题
textarea的readonly属性,不能用setAttribute方法设置,只能类似textarea.readOnly = true|false的写法. 原因: setAttribute只能设置一 ...
- pygrib学习
pygrib-2.0.3/docs/index.html 导入pygrib模块 >>> import pygrib 打开grib文件,获取grib消息迭代器 >>> ...
- netty+proto使用简要记录
1. maven环境配置protobuf 2.生成.proto文件 3.将.proto转为java文件 打开电脑的cmd,进入.proto所在文件位置,输入命令:protoc.exe --java_o ...
- CF刷题-Codeforces Round #481-G. Petya's Exams
题目链接:https://codeforces.com/contest/978/problem/G 题目大意:n天m门考试,每门考试给定三个条件,分别为:1.可以开始复习的日期.2.考试日期.3.必须 ...