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 ...
随机推荐
- GIT与SVN的区别
1.GIT是分布式的,SVN不是: 这是GIT和其它非分布式的版本控制系统,例如SVN,CVS等,最核心的区别.如果你能理解这个概念,那么你就已经上手一半了.需要做一点声明,GIT并不是目前第一个或唯 ...
- 杭电ACM 1197
#include<stdio.h>main(){ int temp,i,t,sum10,sum12,sum16; for(i=1000;i<=9999;i++) { temp=i; ...
- 【代码升级】【iCore3 双核心板】例程二十八:FSMC实验——读写FPGA
实验指导书及代码包下载: http://pan.baidu.com/s/1qXAxwgk iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- array_diff的参数前后循序的区别
//如果两个参数之间有区别.array_diff会返回第二个参数的差值 $oldData = array(0=>'德国',1=>'deguo'); $newData = array(0=& ...
- [转]MongoDB学习 C#驱动操作MongoDB
下载驱动 驱动的下载有两种方式:一种是在C#项目中通过NuGet进行安装,另一种是通过下面的链接:https://github.com/mongodb/mongo-csharp-driver/rele ...
- 有趣的BAT
最近某个用到的第三方程序会产生很多日志文件在logs目录中,每天一个log文件,类似 2014-05-07001.log.日积月累这个目录文件数量非常多,手动清除还是比较麻烦的. 由于这个软件不是自己 ...
- ConcurrentHashMap Put()操作示例代码
非常简练: private static void put(MetricKey key, float value) { MetricValue current; do { current = map. ...
- JMeter学习-002-JMeter环境配置
本节主要介绍 JMeter 本地环境配置(JMeter 版本为 apache-jmeter-2.12),详细配置如下: 一.JDK配置 默认用户本地已经安装且配置好 JDK.若未配置,敬请参阅我的博客 ...
- MyBatis(2):config.xml文件
前言 前一篇文章,讲了MyBatis入门,讲到了MyBatis有两个基本的配置文件,一个用来配置环境信息,一个用来写SQL语句.前者我把它命名为config.xml,config.xml的内容是: 1 ...
- ExtJs、Struts2、Hibernate3.2登录页面的简单实现
1.思想的大致模型 2.建立数据库test和数据库表tb_user 1 CREATEDATABASE `test`; 2 CREATETABLE `test`.`tb_user` ( 3 `user ...