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 ...
随机推荐
- 第 2 章 让jsp说hello
2.1. 另一个简单jsp 上一篇举的例子很单纯,无论谁向服务器发送请求,服务器都只计算当前系统时间,然后把这个时间制作成http响应发还给浏览器. 可惜这种单向的响应没办法实现复杂的业务,比如像这样 ...
- CSS3初学篇章_6(自定义动画)
自定义动画 由于有一部分低版本的浏览器并不支持的问题,所以这个样式要多做兼容,各大浏览器兼容前缀如下: 前缀 浏览器 -webkit chrome和safari -moz firefox - ...
- Rocky4.2下安装达梦(DM)6数据库
1.准备操作系统 1.1 系统登录界面 1.2 操作系统版本信息 jdbh:~ # uname -ra Linux jdbh -x86_64 # SMP Fri Dec :: CST x86_64 G ...
- ajx技术解析以及模拟jQuery封装
1.后台处理程序 <%@ page language="java" contentType="text/html; charset=UTF-8" page ...
- docker pipework
#!/bin/bash #auto install docker and Create VM #Define PATH Varablies IPADDR=`ifconfig |grep "B ...
- 微信公众号内H5调用微信支付国内服务商模式
最近在折微信公众号内H5用JSAPI调用微信支付,境内服务商版支付,微信支付给出的官方文档以及SDK不够详细,导至我们走了一些弯路,把他分享出来,我这边主要是用PHP开发,所以未加说的话示例都是PHP ...
- 解决Android调用https服务API时出错的问题
今天同事告诉我说他的应用调用我开发的API报异常了,原因跟SSL有关系,因为之前调试一直调用的是HTTP服务API,今天调试HTTPS服务API时报错了,并且找到了一篇文章让我看了一眼,文章中提到了W ...
- Android课程---环境配置很重要
- EmguCV+Win7+Visual C# 2012 配置
一.下载与安装OpenCV 安装包版本:OpenCV2.4.2 X86 下载地址:http://sourceforge.net/projects/opencvlibrary/files/opencv- ...
- Print all nodes at distance k from a given node
Given a binary tree, a target node in the binary tree, and an integer value k, print all the nodes t ...