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 ...
随机推荐
- day 84 Vue学习四之过滤器、钩子函数、路由、全家桶等
本节目录 一 vue过滤器 二 生命周期的钩子函数 三 vue的全家桶 四 xxx 五 xxx 六 xxx 七 xxx 八 xxx 一 Vue的过滤器 1 moment.js 在这里我们先介绍一个 ...
- windows下搭建permeate漏洞测试系统实战
最近一直在搭建漏洞测试环境练习. 在此期间遇到很多问题,但是通过学习都一一解决.通过写此文来记录遇到的问题和解决方法. 首先,在github上看到了一个不错的permeate渗透测试系统.于是想搭建拿 ...
- golang中的字符串拼接
go语言中支持的字符串拼接的方法有很多种,这里就来罗列一下 常用的字符串拼接方法 1.最常用的方法肯定是 + 连接两个字符串.这与python类似,不过由于golang中的字符串是不可变的类型,因此用 ...
- golang实现简单的栈
栈的ADT 数据 栈的数据对象集合为{a1,a2,a3...an},具有相同数据类型,有唯一前驱后续 操作 InitStack() *Stack //初始化操作,创建一个空栈 Clear() //清空 ...
- svn版本控制常用命令
查看未提交的文件(含新增的和修改过得) svn status 检出代码 svn checkout svn://192.168.0.10/v2019.1/spark \ /Users/zhangsa ...
- 小技巧textbox的行数
没什么技术含量,但如果不知道则实现起来很麻烦. c#中textbox.lines只记录回车的数量,并不是真正的总行数,如何得到呢,请使用: int 总行数 = this.textBox1.GetLin ...
- ZooKeeper实现分布式队列Queue
ZooKeeper实现分布式队列Queue 让Hadoop跑在云端系列文章,介绍了如何整合虚拟化和Hadoop,让Hadoop集群跑在VPS虚拟主机上,通过云向用户提供存储和计算的服务. 现在硬件越来 ...
- PPAS的MTK tool 工具使用说明
磨砺技术珠矶,践行数据之道,追求卓越价值 回到上一级页面: PostgreSQL基础知识与基本操作索引页 回到顶级页面:PostgreSQL索引页 [作者 高健@博客园 luckyjackg ...
- Hall定理
Hall定理 Tags:图论 zybl 二分图\(G=<V1,V2,E>\)中,\(|V1|<|V2|\),当且仅当\(V1\)中任意\(k(=1,2,3..|V1|)\)个顶点都与 ...
- c++ 文件操作 重新命名 删除
教学内容: l 文件重命名rename l 文件删除remove 文件重命名rename int rename( const char *oldname, const char *newname ...