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 ...
随机推荐
- win10如何让她闭嘴、按什麽建系统都要说话、如何让她闭嘴?
win10如何让她闭嘴.按什麽建系统都要说话.如何让她闭嘴? 开始 设置 轻松使用 讲述人,关掉……
- Java Web项目_部门内部留言板
t_user用户登录数据表 用户登录界面 JSP开发 通过post请求提交给Servlet处理 Servlet处理连接数据库的处理 登陆成功服务器跳转RequestDispatcher到main.js ...
- 【java基础学习】GUI
GUI 容器 布局管理器 组件 菜单 事件处理机制
- [daily][troubleshoot][archlinux][wps][font] wps文档中的图内容无法显示中文
序 用linux作为工作生产环境的几个需要解决的问题之一是:文档协作,即如何兼容Micro$oft Office格式的文档. 我一般的工作方式是:在linux下创建一个win7的虚拟机,安装常用的wi ...
- xmlunit
一个比较方便但也是有点坑的工具. 它能把<struct><int>3</int><boolean>false</boolean></s ...
- 基于XMPP协议(openfire服务器)的消息推送实现
转自:http://blog.csdn.net/nomousewch/article/details/8088277 最近好像有不少朋友关注Android客户端消息推送的实现,我在之前的项目中用到过J ...
- js 十分精确身份证验证
checkIdcard:function (idcard) { // 1 "验证通过!", 0 //身份证号码校验错误 var Errors = new Array( " ...
- java求素数和求一个数的一个正整数的质因数
1.题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少对? (1)程序分析:不难发现兔子的规律是:1,1 ...
- Asp.net导出Excel乱码的解决方法
通过跟踪Asp.net服务器代码,没有乱码,然而导出Excel到浏览器后,打开时出现乱码. 解决方法是添加编码格式的前缀字节码:Response.BinaryWrite(System.Text.Enc ...
- rac one node在线relocation
1.查看数据库运行状态 $ srvctl status database -d rone Instance rone_2 is running on node rone2 Online relocat ...