AtCoder Beginner Contest 050 ABC题
A - Addition and Subtraction Easy
Time limit : 2sec / Memory limit : 256MB
Score : 100 points
Problem Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either +
or -
. Your task is to evaluate the formula instead of her.
Constraints
- 1≦A,B≦109
- op is either
+
or-
.
Input
The input is given from Standard Input in the following format:
A op B
Output
Evaluate the formula and print the result.
Sample Input 1
1 + 2
Sample Output 1
3
Since 1+2=3, the output should be 3.
Sample Input 2
5 - 7
Sample Output 2
-2
解法:没什么好说的
#include<bits/stdc++.h>
using namespace std;
map<int,int>q;
long long h,m;
char s;
int main()
{
scanf("%lld %c %lld",&h,&s,&m);
if(s=='+')
{
printf("%lld\n",h+m);
}
else
{
printf("%lld\n",h-m);
}
return ;
}
B - Contest with Drinks Easy
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement
Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered1 through N. Joisino knows that it takes her Ti seconds to solve problem i(1≦i≦N).
Also, there are M kinds of drinks offered to the contestants, numbered 1 through M. If Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem Pi will become Xi seconds. It does not affect the time to solve the other problems.
A contestant is allowed to take exactly one of the drinks before the start of the contest. For each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink. Here, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems. Your task is to write a program to calculate it instead of her.
Constraints
- All input values are integers.
- 1≦N≦100
- 1≦Ti≦105
- 1≦M≦100
- 1≦Pi≦N
- 1≦Xi≦105
Input
The input is given from Standard Input in the following format:
N
T1 T2 … TN
M
P1 X1
P2 X2
:
PM XM
Output
For each drink, calculate how many seconds it takes Joisino to solve all the problems if she takes that drink, and print the results, one per line.
Sample Input 1
3
2 1 4
2
1 1
2 3
Sample Output 1
6
9
If Joisino takes drink 1, the time it takes her to solve each problem will be 1, 1 and 4 seconds, respectively, totaling 6 seconds.
If Joisino takes drink 2, the time it takes her to solve each problem will be 2, 3 and 4 seconds, respectively, totaling 9 seconds.
Sample Input 2
5
7 2 3 8 5
3
4 2
1 7
4 13
Sample Output 2
19
25
30
题意:告诉你原始的做题时间,现在可以喝饮料,改变对应一个题的做题时间,问按顺序喝饮料,求总的做题时间(每次喝饮料都不影响上下数据,依次独立)
解法:模拟
#include<bits/stdc++.h>
using namespace std;
long long n,m;
long long t[];
long long p;
struct P
{
long long x,y;
}He[];
int main()
{
cin>>n;
for(int i=;i<=n;i++)
{
cin>>t[i];
}
cin>>m;
for(int i=;i<=m;i++)
{
cin>>He[i].x>>He[i].y;
}
for(int i=;i<=m;i++)
{
long long sum=;
for(int j=;j<He[i].x;j++)
{
sum+=t[j];
// cout<<sum<<"A"<<endl;
}
sum+=He[i].y;
// cout<<sum<<"B"<<endl;
for(int j=He[i].x+;j<=n;j++)
{
sum+=t[j];
// cout<<sum<<"C"<<endl;
}
cout<<sum<<endl;
}
return ;
}
C - Lining Up
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is Ai.
Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 109+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.
Constraints
- 1≦N≦105
- 0≦Ai≦N−1
Input
The input is given from Standard Input in the following format:
N
A1 A2 … AN
Output
Print the number of the possible orders in which they were standing, modulo 109+7.
Sample Input 1
5
2 4 4 0 2
Sample Output 1
4
There are four possible orders, as follows:
- 2,1,4,5,3
- 2,5,4,1,3
- 3,1,4,5,2
- 3,5,4,1,2
Sample Input 2
7
6 4 0 2 4 0 2
Sample Output 2
0
Any order would be inconsistent with the reports, thus the answer is 0.
Sample Input 3
8
7 5 1 1 7 3 5 3
Sample Output 3
16
题意:没读懂
解法:首先判断不成立的,当然是出现数字三次以上就算不合法(0不能出现两次以上),然后统计每个数字出现两次的数量,求2^n%mod即可
#include<bits/stdc++.h>
using namespace std;
long long n;
map<long long,long long>q;
map<long long,long long>::iterator it;
long long modl(long long a, long long b, long long c) //快速幂取余a^b%c
{
long long res, t;
res = % c;
t = a % c;
while (b)
{
if (b & )
{
res = res * t % c;
}
t = t * t % c;
b >>= ;
}
return res;
}
long long mod=1e9+;
int main()
{
q.clear();
cin>>n;
for(int i=;i<=n;i++)
{
long long num;
cin>>num;
q[num]++;
}
if(q[]>)
{
cout<<""<<endl;
}
else if(q[]==||q[]==)
{
int num=;
for(it=q.begin();it!=q.end();it++)
{
if(it->second==)
{
num++;
}
else if(it->second>)
{
cout<<""<<endl;
return ;
}
}
num%=mod;
cout<<modl(,num,mod)%mod<<endl;
}
return ;
}
AtCoder Beginner Contest 050 ABC题的更多相关文章
- AtCoder Beginner Contest 068 ABCD题
A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 069 ABCD题
题目链接:http://abc069.contest.atcoder.jp/assignments A - K-City Time limit : 2sec / Memory limit : 256M ...
- AtCoder Beginner Contest 088 (ABC)
A - Infinite Coins 题目链接:https://abc088.contest.atcoder.jp/tasks/abc088_a Time limit : 2sec / Memory ...
- AtCoder Beginner Contest 087 (ABC)
A - Buying Sweets 题目链接:https://abc087.contest.atcoder.jp/tasks/abc087_a Time limit : 2sec / Memory l ...
- AtCoder Beginner Contest 070 ABCD题
题目链接:http://abc070.contest.atcoder.jp/assignments A - Palindromic Number Time limit : 2sec / Memory ...
- AtCoder Beginner Contest 057 ABCD题
A - Remaining Time Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Dol ...
- AtCoder Beginner Contest 051 ABCD题
A - Haiku Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement As a New Yea ...
- AtCoder Beginner Contest 058 ABCD题
A - ι⊥l Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Three poles st ...
随机推荐
- spring security动态管理资源结合自定义登录页面
如果想将动态管理资源与自定义登录页面一起使用,最简单的办法就是在数据库中将登录页面对应的权限设置为IS_AUTHENTICATED_ANONYMOUSLY. 因此在数据库中添加一条资源信息. INSE ...
- zju(11)在IAR中移植ucos到msp430
准备材料 1.在TI官网上下载430的固件库,我用的是msp430f5528的板子,下载的是F5xx_F6xx_Core_Lib 地址http://www.ti.com/tool/msp-exp430 ...
- CentOS 安装
选择选择启动介质 Install or upgrade an existing system: 安装或升级现有的系统 install system with basic video driver: 安 ...
- 节点操作-创建并添加&删除节点&替换&克隆节点
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" ...
- Oracle的自动统计信息不收集直方图的信息
Oracle的自动统计信息不收集直方图的信息 在oracle9i中,默认的统计信息收集是不收集直方图信息的,也就是说默认的MOTHOD_OPT模式为FOR ALL COLUMNS SIZE 1 在10 ...
- P1026 统计单词个数
题意 给出一段字符串和一个字典,把字符串划分为n个连续的子串,求一种最优的划分方式使字符串所含单词数最大.(详见NOIp2001) 思路 这个题是一个很典型的线性dp,难点主要在预处理上. 理解题意后 ...
- bringSubviewToFront和insertSubview: atIndex:
bring方法只能在当前SuperView中改变位置,insertSubview则可以脱离自己的superVIew,成为另个同级甚至高级的view的子view
- 使用NSURLSession
NSURLConnection在iOS9被宣布弃用,NSURLSession从13年发展到现在,终于迎来了它独步江湖的时代.NSURLSession是苹果在iOS7后为HTTP数据传输提供的一系列接口 ...
- MySQL字符编码
数据表tb的col列编码为latin1.而实际存储的字符是gbk编码时,用下面的语句可以查看到非乱码的原始字符串. select convert( binary(col) using gbk) fro ...
- input上传按钮 文字修改办法
解决思路是把input 放在文字的上边,弄成透明的,这样在点文字时,实际是点击了input,这样就实现了文件的上传. 具体代码: <style> #uploadImg{ font-size ...