AtCoder Beginner Contest 051 ABCD题
A - Haiku
Time limit : 2sec / Memory limit : 256MB
Score : 100 points
Problem Statement
As a New Year's gift, Dolphin received a string s of length 19.
The string s has the following format: [five lowercase English letters],[seven lowercase English letters],[five lowercase English letters]
.
Dolphin wants to convert the comma-separated string s into a space-separated string.
Write a program to perform the conversion for him.
Constraints
- The length of s is 19.
- The sixth and fourteenth characters in s are
,
. - The other characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
s
Output
Print the string after the conversion.
Sample Input 1
happy,newyear,enjoy
Sample Output 1
happy newyear enjoy
Replace all the commas in happy,newyear,enjoy
with spaces to obtain happy newyear enjoy
.
Sample Input 2
haiku,atcoder,tasks
Sample Output 2
haiku atcoder tasks
Sample Input 3
abcde,fghihgf,edcba
Sample Output 3
abcde fghihgf edcba
题意:根据样列猜题意
解法:模拟
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
for(int i=;i<s.length();i++)
{
if(s[i]!=',')
{
cout<<s[i];
}
else
{
cout<<" ";
}
}
}
B - Sum of Three Integers
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement
You are given two integers K and S.
Three variable X,Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
How many different assignments of values to X,Y and Z are there such that X+Y+Z=S?
Constraints
- 2≤K≤2500
- 0≤S≤3K
- K and S are integers.
Input
The input is given from Standard Input in the following format:
K S
Output
Print the number of the triples of X,Y and Z that satisfy the condition.
Sample Input 1
2 2
Sample Output 1
6
There are six triples of X,Y and Z that satisfy the condition:
- X=0,Y=0,Z=2
- X=0,Y=2,Z=0
- X=2,Y=0,Z=0
- X=0,Y=1,Z=1
- X=1,Y=0,Z=1
- X=1,Y=1,Z=0
Sample Input 2
5 15
Sample Output 2
1
The maximum value of X+Y+Z is 15, achieved by one triple of X,Y and Z.
题意:看样列猜题意
解法:乍一看感觉是暴力,但不怎么妥当,我这里采用数组保存的方式 500+x+y==s-z记录符合要求的个数
#include<bits/stdc++.h>
using namespace std;
int a[];
int main()
{
int k,s;
cin>>k>>s;
for(int i=;i<=k;i++)
{
for(int j=;j<=k;j++)
{
a[+i+j]++;
}
}
int sum=;
for(int i=;i<=k;i++)
{
int pos=s-i;
if(pos<)
{
continue;
}
sum+=a[+pos];
}
cout<<sum<<endl;
return ;
}
C - Back and Forth
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx<tx and sy<ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point(sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
- −1000≤sx<tx≤1000
- −1000≤sy<ty≤1000
- sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
U
: UpD
: DownL
: LeftR
: Right
If there exist multiple shortest paths under the condition, print any of them.
Sample Input 1
0 0 1 2
Sample Output 1
UURDDLLUUURRDRDDDLLU
One possible shortest path is:
- Going from (sx,sy) to (tx,ty) for the first time: (0,0) → (0,1) → (0,2) → (1,2)
- Going from (tx,ty) to (sx,sy) for the first time: (1,2) → (1,1) → (1,0) → (0,0)
- Going from (sx,sy) to (tx,ty) for the second time: (0,0) → (−1,0) → (−1,1) → (−1,2) → (−1,3) → (0,3) → (1,3) → (1,2)
- Going from (tx,ty) to (sx,sy) for the second time: (1,2) → (2,2) → (2,1) → (2,0) → (2,−1) → (1,−1) → (0,−1) → (0,0)
Sample Input 2
-2 -2 1 1
Sample Output 2
UURRURRDDDLLDLLULUUURRURRDDDLLDL
题意:看样列猜题意
解法:根据提示进行模拟
#include<bits/stdc++.h>
using namespace std;
int a[];
int main()
{
int sx, sy, tx, ty;
cin >> sx >> sy >> tx >> ty;
for(int i=;i<=ty-sy;i++)
{
cout<<"U";
}
for(int i=;i<=tx-sx;i++)
{
cout<<"R";
}
for(int i=;i<=ty-sy;i++)
{
cout<<"D";
}
for(int i=;i<=tx-sx;i++)
{
cout<<"L";
}
cout<<"L";
for(int i=;i<=ty-sy;i++)
{
cout<<"U";
}
cout<<"R";
for(int i=;i<=tx-sx;i++)
{
cout<<"R";
}
cout<<"D";
cout<<"R";
for(int i=;i<=ty-sy;i++)
{
cout<<"D";
}
cout<<"L";
for(int i=;i<=tx-sx;i++)
{
cout<<"L";
}
cout<<"U";
return ;
}
D - Candidates of No Shortest Paths
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges.
The i-th (1≤i≤M) edge connects vertex ai and vertex bi with a distance of ci.
Here, a self-loop is an edge where ai=bi(1≤i≤M), and double edges are two edges where (ai,bi)=(aj,bj) or (ai,bi)=(bj,aj)(1≤i<j≤M).
A connected graph is a graph where there is a path between every pair of different vertices.
Find the number of the edges that are not contained in any shortest path between any pair of different vertices.
Constraints
- 2≤N≤100
- N−1≤M≤min(N(N−1)⁄2,1000)
- 1≤ai,bi≤N
- 1≤ci≤1000
- ci is an integer.
- The given graph contains neither self-loops nor double edges.
- The given graph is connected.
Input
The input is given from Standard Input in the following format:
N M
a1 b1 c1
a2 b2 c2
:
aM bM cM
Output
Print the number of the edges in the graph that are not contained in any shortest path between any pair of different vertices.
Sample Input 1
3 3
1 2 1
1 3 1
2 3 3
Sample Output 1
1
In the given graph, the shortest paths between all pairs of different vertices are as follows:
- The shortest path from vertex 1 to vertex 2 is: vertex 1 → vertex 2, with the length of 1.
- The shortest path from vertex 1 to vertex 3 is: vertex 1 → vertex 3, with the length of 1.
- The shortest path from vertex 2 to vertex 1 is: vertex 2 → vertex 1, with the length of 1.
- The shortest path from vertex 2 to vertex 3 is: vertex 2 → vertex 1 → vertex 3, with the length of 2.
- The shortest path from vertex 3 to vertex 1 is: vertex 3 → vertex 1, with the length of 1.
- The shortest path from vertex 3 to vertex 2 is: vertex 3 → vertex 1 → vertex 2, with the length of 2.
Thus, the only edge that is not contained in any shortest path, is the edge of length 3 connecting vertex 2 and vertex 3, hence the output should be 1.
Sample Input 2
3 2
1 2 1
2 3 1
Sample Output 2
0
Every edge is contained in some shortest path between some pair of different vertices.
题意:让我们找出不含最短路径的道路有多少条
解法:先Floyd跑一次,然后比较原始道路和现在的道路,距离不同就说明最短路径也不经过这条道路,然后加一
#include<bits/stdc++.h>
using namespace std;
long long a[][];
long long b[][];
int inf=(<<)-;
int main()
{
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
a[i][j]=inf;
b[i][j]=inf;
}
b[i][i]=;
a[i][i]=;
}
for(int i=;i<=m;i++)
{
long long x,y,z;
cin>>x>>y>>z;
a[x][y]=min(z,a[x][y]);
a[y][x]=min(z,a[y][x]);
b[x][y]=min(z,b[x][y]);
b[y][x]=min(z,b[y][x]);
}
for(int k=;k<=n;k++)
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
a[i][j]=min(a[i][k]+a[k][j],a[i][j]);
// cout<<a[i][j]<<" "<<i<<" "<<j<<" "<<k<<endl;
}
}
}
int sum=;
for(int i=;i<=n;i++)
{
for(int j=+i;j<=n;j++)
{
if(b[i][j]!=inf&&a[i][j]!=b[i][j])
{
sum++;
//cout<<i<<" "<<j<<endl;
// cout<<a[i][j]<<" "<<b[i][j]<<endl;
}
}
}
cout<<sum<<endl;
// cout<<b[1][2]<<endl;
return ;
}
AtCoder Beginner Contest 051 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 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 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 ...
随机推荐
- 关于MySQL的information_schema库简单介绍及实际应用
本文简介 写本文主要是围绕下面几点进行的. 1.information_schema数据库到底是做什么用的? 2.执行alter table 表名 modify column 字段名 类型 这个sql ...
- codeforces B. Coach 解题报告
题目链接:http://codeforces.com/problemset/problem/300/B 题目意思:给出n个students(n%3 = 0),编号依次为1-n,接下来有m行,每行有两个 ...
- 英语发音规则---s发/s/的读音规则
英语发音规则---s发/s/的读音规则 一.总结 一句话总结:字母s的读音有/s/./z/./ʃ/./{/这几种,下面主要讲讲发/s/音的几条规则. 字母s的读音有/s/./z/./ʃ/./{/这几种 ...
- jsp报An error has occurred. See error log for more details. Argument not valid错误
An error has occurred. See error log for more details. Argument not valid 翻译过来是:一个错误已经发生.看到更多的细节错误日志 ...
- touch实现滑动删除
请用chrome手机模式查看或者在手机上查看(转载请注明出处) <!DOCTYPE html> <html> <head> <meta charset=&qu ...
- NOI2017退役记
Day1 全世界都200+我162,考场上fread和fwrite写挂了直接删了,然后就被卡了48也是没谁了. Day2 2-SAT写挂,就没有然后了. 明明退役前一直都在做自己最想做的事情,连这就是 ...
- TX2上yolov3精度和速度优化方向
速度优化的方向: 1.减少输入图片的尺寸, 但是相应的准确率可能会有所下降2.优化darknet工程源代码(去掉一些不必要的运算量或者优化运算过程)3.剪枝和量化yolov3网络(压缩模型---> ...
- bzoj 5092 分割序列 —— 高维前缀和
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=5092 首先,处理出异或前缀和 s[i],i 位置的答案就是 s[j] + s[j]^s[i] ...
- bzoj1013高斯消元
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1013 似乎是很明显的高斯消元: 第一次写高斯消元. 代码如下: #include<io ...
- Nagios监控Windows的网卡流量
Nagios监控Windows的网卡流量 使用/usr/local/nagios/libexec/中的check_traffic.sh,不但可以监控Linux的网卡流量,也可以监控Windows服务器 ...