AtCoder Beginner Contest 070 ABCD题
题目链接:http://abc070.contest.atcoder.jp/assignments
A - Palindromic Number
Time limit : 2sec / Memory limit : 256MB
Score : 100 points
Problem Statement
You are given a three-digit positive integer N.
Determine whether N is a palindromic number.
Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
Constraints
- 100≤N≤999
- N is an integer.
Input
Input is given from Standard Input in the following format:
- N
Output
If N is a palindromic number, print Yes
; otherwise, print No
.
Sample Input 1
- 575
Sample Output 1
- Yes
N=575 is also 575 when read backward, so it is a palindromic number. You should print Yes
.
Sample Input 2
- 123
Sample Output 2
- No
N=123 becomes 321 when read backward, so it is not a palindromic number. You should print No
.
Sample Input 3
- 812
Sample Output 3
- No
- 题解:水水
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <string>
- #include <cmath>
- using namespace std;
- #define ll long long
- const int N=;
- const int mod=1e9+;
- const int maxn=1e7;
- int main()
- {
- int n;
- while(cin>>n){
- int a=n/;
- int b=(b-a*)/;
- int c=n%;
- if(a==c) cout<<"Yes"<<endl;
- else cout<<"No"<<endl;
- }
- return ;
- }
B - Two Switches
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement
Alice and Bob are controlling a robot. They each have one switch that controls the robot.
Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up.
Bob started holding down his button C second after the start-up, and released his button D second after the start-up.
For how many seconds both Alice and Bob were holding down their buttons?
Constraints
- 0≤A<B≤100
- 0≤C<D≤100
- All input values are integers.
Input
Input is given from Standard Input in the following format:
- A B C D
Output
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.
Sample Input 1
- 0 75 25 100
Sample Output 1
- 50
Alice started holding down her button 0 second after the start-up of the robot, and released her button 75 second after the start-up.
Bob started holding down his button 25 second after the start-up, and released his button 100 second after the start-up.
Therefore, the time when both of them were holding down their buttons, is the 50 seconds from 25 seconds after the start-up to 75 seconds after the start-up.
Sample Input 2
- 0 33 66 99
Sample Output 2
- 0
Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds.
Sample Input 3
- 10 90 20 80
Sample Output 3
- 60
- 题解:分情况讨论即可
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <string>
- #include <cmath>
- using namespace std;
- #define ll long long
- const int N=;
- const int mod=1e9+;
- const int maxn=1e7;
- int main()
- {
- int a,b,c,d;
- while(cin>>a>>b>>c>>d){
- if(c>b||a>d) cout<<<<endl;
- else if(a<=c&&d<=b){
- cout<<d-c<<endl;
- }
- else if(c<=a&&b<=d){
- cout<<b-a<<endl;
- }
- else if(a<=c&&c<=b&&b<=d){
- cout<<b-c<<endl;
- }
- else if(c<=a&&a<=d&&d<=b){
- cout<<d-a<<endl;
- }
- }
- return ;
- }
C - Multiple Clocks
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly Ti seconds.
Initially, the hand of every clock stands still, pointing directly upward.
Now, Dolphin starts all the clocks simultaneously.
In how many seconds will the hand of every clock point directly upward again?
Constraints
- 1≤N≤100
- 1≤Ti≤1018
- All input values are integers.
- The correct answer is at most 1018 seconds.
Input
Input is given from Standard Input in the following format:
- N
- T1
- :
- TN
Output
Print the number of seconds after which the hand of every clock point directly upward again.
Sample Input 1
- 2
- 2
- 3
Sample Output 1
- 6
We have two clocks. The time when the hand of each clock points upward is as follows:
- Clock 1: 2, 4, 6, … seconds after the beginning
- Clock 2: 3, 6, 9, … seconds after the beginning
Therefore, it takes 6 seconds until the hands of both clocks point directly upward.
Sample Input 2
- 5
- 2
- 5
- 10
- 1000000000000000000
- 1000000000000000000
Sample Output 2
- 1000000000000000000
- 题解:就是求最小公倍数 (如果只有一个数直接输出)
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <string>
- #include <cmath>
- using namespace std;
- #define ll long long
- const int N=;
- const int mod=1e9+;
- const int maxn=1e7;
- ll a[];
- ll gcd(ll x,ll y)
- {
- ll c;
- ll m=x,n=y;
- while(y!=){
- c=x%y;
- x=y;
- y=c;
- }
- return m/x*n;
- }
- int main()
- {
- int n;
- cin>>n;
- ll m,s,l;
- cin>>m;
- if(n==) cout<<m<<endl;
- else if(n>){
- cin>>l;
- s=gcd(l,m);
- for(int i=;i<n-;i++){
- cin>>m;
- s=gcd(s,m);
- }
- cout<<s<<endl;
- }
- return ;
- }
D - Transit Tree Path
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
You are given a tree with N vertices.
Here, a tree is a kind of graph, and more specifically, a connected undirected graph with N−1 edges, where N is the number of its vertices.
The i-th edge (1≤i≤N−1) connects Vertices ai and bi, and has a length of ci.
You are also given Q queries and an integer K. In the j-th query (1≤j≤Q):
- find the length of the shortest path from Vertex xj and Vertex yj via Vertex K.
Constraints
- 3≤N≤105
- 1≤ai,bi≤N(1≤i≤N−1)
- 1≤ci≤109(1≤i≤N−1)
- The given graph is a tree.
- 1≤Q≤105
- 1≤K≤N
- 1≤xj,yj≤N(1≤j≤Q)
- xj≠yj(1≤j≤Q)
- xj≠K,yj≠K(1≤j≤Q)
Input
Input is given from Standard Input in the following format:
- N
- a1 b1 c1
- :
- aN−1 bN−1 cN−1
- Q K
- x1 y1
- :
- xQ yQ
Output
Print the responses to the queries in Q lines.
In the j-th line j(1≤j≤Q), print the response to the j-th query.
Sample Input 1
- 5
- 1 2 1
- 1 3 1
- 2 4 1
- 3 5 1
- 3 1
- 2 4
- 2 3
- 4 5
Sample Output 1
- 3
- 2
- 4
The shortest paths for the three queries are as follows:
- Query 1: Vertex 2 → Vertex 1 → Vertex 2 → Vertex 4 : Length 1+1+1=3
- Query 2: Vertex 2 → Vertex 1 → Vertex 3 : Length 1+1=2
- Query 3: Vertex 4 → Vertex 2 → Vertex 1 → Vertex 3 → Vertex 5 : Length 1+1+1+1=4
Sample Input 2
- 7
- 1 2 1
- 1 3 3
- 1 4 5
- 1 5 7
- 1 6 9
- 1 7 11
- 3 2
- 1 3
- 4 5
- 6 7
Sample Output 2
- 5
- 14
- 22
The path for each query must pass Vertex K=2.
Sample Input 3
- 10
- 1 2 1000000000
- 2 3 1000000000
- 3 4 1000000000
- 4 5 1000000000
- 5 6 1000000000
- 6 7 1000000000
- 7 8 1000000000
- 8 9 1000000000
- 9 10 1000000000
- 1 1
- 9 10
Sample Output 3
- 17000000000
- 题解:dfs
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <string>
- #include <algorithm>
- using namespace std;
- const int maxn = 1e5+;
- const int N = ;
- typedef long long ll;
- int t,head[maxn];
- ll dist[maxn],w;
- bool vis[maxn];
- struct Edge
- {
- int from,to,nxt;
- ll cost;
- }e[*maxn];
- void addedge(int u,int v,int w)
- {
- e[t].from=u;
- e[t].to=v;
- e[t].cost=w;
- e[t].nxt=head[u];
- head[u]=t++;
- }
- void dfs(int u,int fa)
- {
- for(int i=head[u];i!=-;i=e[i].nxt){
- int to=e[i].to;
- if(to==fa) continue;
- dist[to]=dist[u]+e[i].cost;
- dfs(to,u);
- }
- }
- int main()
- {
- int n;
- while(cin>>n){
- t=;
- memset(head,-,sizeof(head));
- memset(dist,,sizeof(dist));
- int u,v;
- for(int i=;i<n;i++){
- cin>>u>>v>>w;
- addedge(u,v,w);
- addedge(v,u,w);
- }
- int q,k;
- cin>>q>>k;
- dfs(k,-);
- int x,y;
- for(int i=;i<q;i++){
- cin>>x>>y;
- cout<<dist[x]+dist[y]<<endl;
- }
- }
- return ;
- }
AtCoder Beginner Contest 070 ABCD题的更多相关文章
- 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 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 052 ABCD题
A - Two Rectangles Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement The ...
- AtCoder Beginner Contest 054 ABCD题
A - One Card Poker Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Ali ...
- AtCoder Beginner Contest 058 ABCD题
A - ι⊥l Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Three poles st ...
- AtCoder Beginner Contest 050 ABC题
A - Addition and Subtraction Easy Time limit : 2sec / Memory limit : 256MB Score : 100 points Proble ...
随机推荐
- 前端 HTML body标签相关内容 常用标签 段落标签 p标签
段落标签 <p>,paragraph的简写.定义段落,默认段落之间有间隔的 浏览器展示特点: 跟普通文本一样,但我们可以通过css来设置当前段落的样式 是否又独占一行呢? 答案是的 块级元 ...
- 防止SQL注入的6个要点
SQL注入,就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.防止SQL注入,我们可以从以下6个要点来进行: 1.永远不要信任用户的输入 ...
- 数据库——MySQL及安装
what's the MySQL MySQL是一个关系型数据库管理系统,MySQL 是目前最流行的关系型数据库管理系统之一,在 WEB 应用方面MySQL是最好的 RDBMS (Relational ...
- abap中结构体嵌套结构体。
1: 结构体中嵌套结构体. *&---------------------------------------------------------------------* *& Re ...
- springboot测试
一.单元测试 在开发阶段的时候最重要的是单元测试了,springboot对单元测试的支持已经很完善了. 1.在pom包中添加spring-boot-starter-test包引用 <depend ...
- python 微信机器人,微信自动回复
使用python现成的模块 itchat,可以实现,微信机器人的自动回复 其内部原理,是模拟了web版微信的登录,然后进行消息的接收发送,并不是只能用python实现,其他后端语言都可以做到 下面是使 ...
- iOS 新浪微博-1.1框架升级
在iOS 新浪微博-1.0框架搭建 中,使用的是xcode5.1.1开发.现在把重整了一下框架 改为xcode7.0开发 使用cocoaPad管理第三方库 程序将托管到github上 在改为xcode ...
- C++ 退出双层for循环,解决 break、return、continue无法实现问题
遇到一个情景,采用双层for循环 遍历图像的像素,当找到某一个像素点满足条件时,退出双层for 循环 . 首先了解一下 continue.break.return 各自功能用法: 1.continue ...
- Ecshop 表结构 字段说明
ecs_account_log 用户帐号情况记录表,包括资金和积分等 log_id mediumint 自增ID号user_id mediumint 用户登录后保存在session中的id号,跟use ...
- vue中上传图片至阿里云oss
1.开通阿里云的oss服务这些这里就不多做介绍了 2.登入阿里云的后台管理系统创建一个Bucket 3.在后台管理系统中进入访问控制 4.点击用户管理->新建用户->填写相关信息,就生成了 ...