题目链接: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

Copy
575

Sample Output 1

Copy
Yes

N=575 is also 575 when read backward, so it is a palindromic number. You should print Yes.


Sample Input 2

Copy
123

Sample Output 2

Copy
No

N=123 becomes 321 when read backward, so it is not a palindromic number. You should print No.


Sample Input 3

Copy
812

Sample Output 3

Copy
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

Copy
0 75 25 100

Sample Output 1

Copy
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

Copy
0 33 66 99

Sample Output 2

Copy
0

Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds.


Sample Input 3

Copy
10 90 20 80

Sample Output 3

Copy
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≤iN) 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

Copy
2
2
3

Sample Output 1

Copy
6

We have two clocks. The time when the hand of each clock points upward is as follows:

  • Clock 1246 seconds after the beginning
  • Clock 2369 seconds after the beginning

Therefore, it takes 6 seconds until the hands of both clocks point directly upward.


Sample Input 2

Copy
5
2
5
10
1000000000000000000
1000000000000000000

Sample Output 2

Copy
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≤iN−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≤jQ):

  • find the length of the shortest path from Vertex xj and Vertex yj via Vertex K.

Constraints

  • 3≤N≤105
  • 1≤ai,biN(1≤iN−1)
  • 1≤ci≤109(1≤iN−1)
  • The given graph is a tree.
  • 1≤Q≤105
  • 1≤KN
  • 1≤xj,yjN(1≤jQ)
  • xjyj(1≤jQ)
  • xjK,yjK(1≤jQ)

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≤jQ), print the response to the j-th query.


Sample Input 1

Copy
5
1 2 1
1 3 1
2 4 1
3 5 1
3 1
2 4
2 3
4 5

Sample Output 1

Copy
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

Copy
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

Copy
5
14
22

The path for each query must pass Vertex K=2.


Sample Input 3

Copy
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

Copy
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题的更多相关文章

  1. AtCoder Beginner Contest 068 ABCD题

    A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...

  2. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  3. AtCoder Beginner Contest 069 ABCD题

    题目链接:http://abc069.contest.atcoder.jp/assignments A - K-City Time limit : 2sec / Memory limit : 256M ...

  4. AtCoder Beginner Contest 057 ABCD题

    A - Remaining Time Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Dol ...

  5. AtCoder Beginner Contest 051 ABCD题

    A - Haiku Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement As a New Yea ...

  6. AtCoder Beginner Contest 052 ABCD题

    A - Two Rectangles Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement The ...

  7. AtCoder Beginner Contest 054 ABCD题

    A - One Card Poker Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Ali ...

  8. AtCoder Beginner Contest 058 ABCD题

    A - ι⊥l Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Three poles st ...

  9. AtCoder Beginner Contest 050 ABC题

    A - Addition and Subtraction Easy Time limit : 2sec / Memory limit : 256MB Score : 100 points Proble ...

随机推荐

  1. 误删除innodb ibdata数据文件 文件句柄 文件描述符 proc fd

    误删除innodb ibdata数据文件  文件句柄  文件描述符  proc  fd http://www.cnblogs.com/gomysql/p/3702216.html 提示:如果不小心通过 ...

  2. maven 安装 配置

    一.下载及安装 1.1 下载maven 3.1.1 先到官网http://maven.apache.org/download.cgi 下载最新版本(目前是3.1.1 ),下载完成后,解压到某个目录(本 ...

  3. sap QG3搜索

    先创建一个QG3系统,创建一个用户. 1: 进入搜索模板 2: 选择软件组件,点击执行 3: 设置过滤条件. 4: 选择在哪一列 设置过滤条件. 5: 定义搜索值 6: 设置值 可以将搜索的结果删除. ...

  4. 向github提交代码总是要输入用户名密码

    在命令行输入命令: $ git config --global credential.helper store 这一步会在用户目录下的.gitconfig文件最后添加: [credential]    ...

  5. [vue]webpack3最佳实践篇

    vue-render: https://www.cnblogs.com/iiiiiher/articles/9465311.html es6模块的导入导出 https://www.cnblogs.co ...

  6. Java知识点-判断null、空字符串和空格

    Java知识点-判断null.空字符串和空格 // 判断headerKey是否为null,空字符串或者空格 if (headerKey != null && headerKey.len ...

  7. 【LeetCode每天一题】Remove Nth Node From End of List(移除链表倒数第N个节点)

    Given a linked list, remove the n-th node from the end of list and return its head. Example:        ...

  8. mybatis oracle 插入自增记录 获取主键值 写回map参数

    网上搜了好多文章照着弄都返回不了主键给map, 实践证明要在传入的map参数里写回插入的主键,要这样写 <selectKey resultType="java.lang.Integer ...

  9. GO language

    看到有人说GO是未来10年的主流了,不论是速度迅速接近于C,还是语法简洁接近于C,结果尽然还是编译型的,不需要虚拟机,生成程序已经是本地字节码. 得,我不淡定了,这个不学,枉为程序员啊. 今天,讲讲l ...

  10. 第三章Div水平居中

    1.div居中 text-align:center可以让元素里面的文字内容居中,但并不能让div居中.要让div水平居中必须设置div宽度,外边距设置为margin:0 auto <%@ Pag ...