愚人节过后,又打了一场ABC。
结果:A,B题 AC(300分),C题RE,赛后AC,D题不会,瞎写了个TLE代码,没水过去。
(↑↑↑↑↑ 赛时部分记录 ↑↑↑↑↑)
目录
网址
AtCoder Beginner Contest 246 - AtCoderhttps://atcoder.jp/contests/abc246
结果:A,B(300分)。
A题
题目描述
A - Four Points /
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 100 points
Problem Statement
There is a rectangle in the xy-plane. Each edge of this rectangle is parallel to the x- or y-axis, and its area is not zero.
Given the coordinates of three of the four vertices of this rectangle, (x
1
,y
1
), (x
2
,y
2
), and (x
3
,y
3
), find the coordinates of the other vertex.
Constraints
−100≤x
i
,y
i
≤100
There uniquely exists a rectangle with all of (x
1
,y
1
), (x
2
,y
2
), (x
3
,y
3
) as vertices, edges parallel to the x- or y-axis, and a non-zero area.
All values in input are integers.
Input
Input is given from Standard Input in the following format:
x
1
y
1
x
2
y
2
x
3
y
3
Output
Print the sought coordinates (x,y) separated by a space in the following format:
x y
Sample Input 1
Copy
-1 -1
-1 2
3 2
Sample Output 1
Copy
3 -1
The other vertex of the rectangle with vertices (−1,−1),(−1,2),(3,2) is (3,−1).
Sample Input 2
Copy
-60 -40
-60 -80
-20 -80
Sample Output 2
Copy
-20 -40
题目分析
题目大意:输入一个长方形三个角的坐标,输出第四个的x,y坐标,用空格隔开两数。
思路:来俩map储存一下每个数字出现的次数,最后两map中个数为1的(不是0或2),即第四个角的x,y坐标。
题目代码
AC代码(此题有点水):
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
map<int,int>mp;
map<int,int>mq;
for(int i=-110;i<110;i++){
mp[i]=0;
mq[i]=0;
}
int a[10],b[10],p,q;
for(int i=0;i<3;i++)
cin>>a[i]>>b[i];
for(int i=0;i<3;i++){
mp[a[i]]++;
mq[b[i]]++;
}
for(int i=-110;i<110;i++){
if(mp[i]==1)
p=i;
if(mq[i]==1)
q=i;
}
cout<<p<<" "<<q;
return 0;
}
//ACplease!!!
/* printf(" \n");
printf(" \n");
printf(" * * * * * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * \n");
*/
知识讲解
这次学习其他大佬,使用signed main()主函数,强烈推荐!!!
B题
题目描述
B - Get Closer /
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 200 points
Problem Statement
From the point (0,0) in a two-dimensional plane, let us move the distance of 1 toward the point (A,B). Find our coordinates after the move.
Here, after moving the distance of d from a point X to a point Y (d≤ length of the segment XY), we are at the point on the segment XY whose distance from X is d.
The Constraints guarantee that the distance between the points (0,0) and (A,B) is at least 1.
Constraints
All values in input are integers.
0≤A,B≤1000
(A,B)
=(0,0)
Input
Input is given from Standard Input in the following format:
A B
Output
Let (x,y) be our coordinates after the move. Print x and y in this order, separated by a space.
Your output is considered correct when, for each printed value, the absolute or relative error from the judge's answer is at most 10
−6
.
Sample Input 1
Copy
3 4
Sample Output 1
Copy
0.600000000000 0.800000000000
Printing 0.5999999999 0.8000000001, for example, would also be accepted.
Sample Input 2
Copy
1 0
Sample Output 2
Copy
1.000000000000 0.000000000000
We may arrive at (A,B).
Sample Input 3
Copy
246 402
Sample Output 3
Copy
0.521964870245 0.852966983083
题目分析
题目大意:从二维平面上的点(0,0)开始,让我们向点(A,B)移动距离1。移动后找到我们的坐标,误差不超过0.000001(10的-6次方,10^-6)。
思路:勾股定理+相似三角形(这次B题不太友好)。
题目代码
AC代码(此题有点水):
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int a,b;
cin>>a>>b;
double d=hypot(a,b),x,y;
x=a/d;
y=b/d;
cout<<x<<" "<<y;
return 0;
}
//ACplease!!!
/* printf(" \n");
printf(" \n");
printf(" * * * * * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * \n");
*/
知识讲解
这里涉及hypot函数。
hypot函数的作用:用于查找给定三角形的斜边,接受两个数字并返回斜边的计算结果,有可用sqrt(x*x+y*y)表示。
这里举个“栗子”:
#include<bits/stdc++.h>
using namespace std;
int main()
{
double a,b;
cout<<"hypot函数的作用:用于查找给定三角形的斜边,接受两个数字并返回斜边的计算结果,有可用sqrt(x*x+y*y)表示"<<endl;
cout<<"请输入两个整数或小数(表示三角形的两条直角边):";
cin>>a>>b;
double ans=hypot(a,b);
cout<<"勾"<<a<<"股"<<b<<"弦"<<ans<<"。(结果保留小数点后6位)";
return 0;
}
C题
题目描述
C - Coupon /
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 300 points
Problem Statement
There are N items in a shop. For each i=1,2,…,N, the price of the i-th item is A
i
yen (the currency of Japan).
Takahashi has K coupons.
Each coupon can be used on one item. You can use any number of coupons, possibly zero, on the same item. Using k coupons on an item with a price of a yen allows you to buy it for max{a−kX,0} yen.
Print the minimum amount of money Takahashi needs to buy all the items.
Constraints
1≤N≤2×10
5
1≤K,X≤10
9
1≤A
i
≤10
9
All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K X
A
1
A
2
… A
N
Output
Print the answer.
Sample Input 1
Copy
5 4 7
8 3 10 5 13
Sample Output 1
Copy
12
By using 1 coupon on the 1-st item, 1 coupon on the 3-rd item, and 2 coupons on the 5-th item, Takahashi can:
buy the 1-st item for max{A
1
−X,0}=1 yen,
buy the 2-nd item for max{A
2
,0}=3 yen,
buy the 3-rd item for max{A
3
−X,0}=3 yen,
buy the 4-th item for max{A
4
,0}=5 yen,
buy the 5-th item for max{A
5
−2X,0}=0 yen,
for a total of 1+3+3+5+0=12 yen, which is the minimum possible.
Sample Input 2
Copy
5 100 7
8 3 10 5 13
Sample Output 2
Copy
0
Sample Input 3
Copy
20 815 60
2066 3193 2325 4030 3725 1669 1969 763 1653 159 5311 5341 4671 2374 4513 285 810 742 2981 202
Sample Output 3
Copy
112
题目分析
题目大意:
商店里有N种商品。第i项的价格为Ai yen(日元)。高桥有K优惠券。每张优惠券可用于一个项目。你可以在同一件商品上使用任意数量的优惠券,可能为零。在价格为一日元的物品上使用k优惠券可以让你以max{a−kX,0}日元。打印高桥购买所有物品所需的最低金额。
思路:俺不解释了,看下面两个代码中的AC码(下面那一个),看完就懂了。反正就是sort排序挨个看呗。
题目代码
赛时RE代码(无可奈何花落去):
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,x,a[20022],sum=0,t=0;
cin>>n>>k>>x;
for(int i=0;i<n;i++){
cin>>a[i];
t+=a[i];
}
sort(a,a+n);
for(int i=n-1;i>=0;i--){
int d=round((double)a[i]/(double)x);
if(k-d>=0){
k-=d;
sum+=max((int)a[i]-d*x,0);
}else{
sum+=a[i];
}
}
if(t<=k*x) sum=0;
cout<<sum;
return 0;
}
//ACplease!!!
/* printf(" \n");
printf(" \n");
printf(" * * * * * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * \n");
*/
赛后AC代码(好简单,估计是打比赛时脑子坏了):
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,k,x,a[200022],sum=0;
cin>>n>>k>>x;
for(long long i=0;i<n;i++){
cin>>a[i];
long long mn=min(k,a[i]/x);
a[i]-=mn*x;
k-=mn;
}
sort(a,a+n);
for(long long i=n-1;i>=0;i--){
if(k){
a[i]=0;
k--;
}
sum+=a[i];
}
cout<<sum;
return 0;
}
//ACplease!!!
/* printf(" \n");
printf(" \n");
printf(" * * * * * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * \n");
*/
D题
题目描述
D - 2-variable Function /
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 400 points
Problem Statement
Given an integer N, find the smallest integer X that satisfies all of the conditions below.
X is greater than or equal to N.
There is a pair of non-negative integers (a,b) such that X=a
3
+a
2
b+ab
2
+b
3
.
Constraints
N is an integer.
0≤N≤10
18
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer as an integer.
Sample Input 1
Copy
9
Sample Output 1
Copy
15
For any integer X such that 9≤X≤14, there is no (a,b) that satisfies the condition in the statement.
For X=15, (a,b)=(2,1) satisfies the condition.
Sample Input 2
Copy
0
Sample Output 2
Copy
0
N itself may satisfy the condition.
Sample Input 3
Copy
999999999989449206
Sample Output 3
Copy
1000000000000000000
Input and output may not fit into a 32-bit integer type.
题目分析
题目大意:给定一个整数N,找到满足以下所有条件的最小整数X。
1.X大于或等于N。
2.存在一对非负整数(a,b)。
思路:没思路,瞎写的。。。。。。
题目代码
TLE代码,妥妥的:
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
long long n;
cin>>n;
for(int i=n;;i++)
for(int j=0;j<=sqrt(i);j++)
for(int k=j;k<=sqrt(i);k++)
if(i==j*j*j+j*j*k+j*k*k+k*k*k){
cout<<i;
return 0;
}
return 0;
}
//ACplease!!!
/* printf(" \n");
printf(" \n");
printf(" * * * * * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * \n");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * \n");
*/
其它
都没做……
呵呵o(* ̄︶ ̄*)o,继续努力吧!(排名:不提了)
我的Atcoder账号
joe_zxq
版权声明
————————————————
版权声明:本文为CSDN博主「joe_zxq21」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明, 不欢迎 欢迎大家的转载和关注。