当前位置:网站首页>AtCoder Beginner Contest 258(A-D)
AtCoder Beginner Contest 258(A-D)
2022-07-03 05:35:00 【. Ashy.】
A - When?
The main points of : Format output time
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+7;
int n;
int main()
{
cin>>n;
int h=n/60+21;
int m=n%60;
printf("%02d:%02d",h,m);
}
B Number Box
Be careful :
Note that the search is in eight straight directions , Instead of searching eight directions every time , Because no matter how to search the string length, it is certain , So we only start with the largest number at the beginning
Pay attention to the questions
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+7;
int n;
char a[21][21];
int max1;
string ans="";
int dir[8][2]={
0,1,0,-1,1,0,-1,0,1,1,1,-1,-1,1,-1,-1};
void serch(int x,int y)
{
string s1="";
int xx=x;
for(int i=1;i<=n;i++)
{
s1+=a[xx][y];
xx++;
if(xx>n) xx=1;
}// Right
ans=max(ans,s1);
s1="";
xx=x;
for(int i=1;i<=n;i++)
{
s1+=a[xx][y];
xx--;
if(xx<1) xx=n;
}// Left
ans=max(ans,s1);
s1="";
int yy=y;
for(int i=1;i<=n;i++)
{
s1+=a[x][yy];
yy++;
if(yy>n) yy=1;
}// On
ans=max(ans,s1);
s1="";yy=y;
for(int i=1;i<=n;i++)
{
s1+=a[x][yy];
yy--;
if(yy<1) yy=n;
}// Next
ans=max(ans,s1);
s1="";xx=x,yy=y;
for(int i=1;i<=n;i++)
{
s1+=a[xx][yy];
xx--;
yy--;
if(xx<1) xx=n;
if(yy<1) yy=n;
}// Top left
ans=max(ans,s1);
s1="";xx=x,yy=y;
for(int i=1;i<=n;i++)
{
s1+=a[xx][yy];
xx++;
yy++;
if(xx>n) xx=1;
if(yy>n) yy=1;
}// The lower right
ans=max(ans,s1);
s1="";xx=x,yy=y;
for(int i=1;i<=n;i++)
{
s1+=a[xx][yy];
xx++;
yy--;
if(xx>n) xx=1;
if(yy<1) yy=n;
}// The upper right
ans=max(ans,s1);
s1="";xx=x,yy=y;
for(int i=1;i<=n;i++)
{
s1+=a[xx][yy];
xx--;
yy++;
if(xx<1) xx=n;
if(yy>n) yy=1;
}// The lower left
ans=max(ans,s1);
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++) ans+='1';
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
max1=max(max1,a[i][j]-'0');
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(a[i][j]-'0'==max1)
{
serch(i,j);
}
}
}
cout<<ans;
}
C Rotation
Ideas :
We use it k Represents the number of shift operations , When k == n Time is equivalent to no movement Then the number of effective moves is k%n , Then the original header is equivalent to being moved to n-k The location of , Requirement No b Letters , That's it n-k+b The letter of position , Of course , This number should also be correct n Remainder , If you exceed n
Represents that this number has been moved to the front , So take the rest .
Be sure to note that the remainder equals 0 Does the situation of have an impact on the problem !!!!
Try more groups of examples !!!
Pay attention long long
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+7;
ll n,m;
string s;
ll a,b,k,sum;
int main()
{
cin>>n>>m;
cin>>s;
for(int i=1;i<=m;i++)
{
scanf("%lld %lld",&a,&b);
if(a==1)
{
k+=b;
k=k%n;
}
else
{
int kk=((n-k)+b)%n;if(kk==0) kk=n;
cout<<s[kk-1]<<endl;
}
}
}
D:Trophy
The question :
n Stages , From the first stage , Each new stage will cost a+b , Staying in the unlocked phase only costs b , ask Handle X What is the minimum cost of the second stage
Ideas :
We need to find a smaller one b, Make most of The treatment of is in b On , Not in a+b On , Make the cost smaller , So the idea of this question is to unlock each stage , Then process all the remaining processing times in this stage, that is, spend this b , At every stage b Try it all once , Minimum value .
Note that the data is relatively large , open ull
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int N = 1e5+7;
ll min1=1e19+10;
ll n,t;
ll a,b;
ll sum;
int main()
{
cin>>n>>t;
for(int i=1;i<=n;i++)
{
scanf("%llu %llu",&a,&b);
sum+=(a+b);
min1=min(min1,sum+b*(t-i));
}
cout<<min1;
}
边栏推荐
- Explanation of variables, code blocks, constructors, static variables and initialization execution sequence of static code blocks of Ali interview questions
- Redis 击穿穿透雪崩
- 获取并监控远程服务器日志
- 期末复习(Day2)
- Transferring images using flask
- Source insight License Activation
- es7创建索引容易犯的错误
- Introduction to redis and explanation of data types
- The request database reported an error: "could not extract resultset; SQL [n/a]; needed exception is org.hibernate.exception.sqlgram"
- Webrtc protocol introduction -- an article to understand ice, stun, NAT, turn
猜你喜欢
Technical analysis of qianyuantong multi card aggregation router
About debugging the assignment of pagenum and PageSize of the formal parameter pageweb < T > (i.e. page encapsulation generic) in the controller
Go practice -- factory mode of design patterns in golang (simple factory, factory method, abstract factory)
Mapbox tasting value cloud animation
大学校园IP网络广播-厂家基于校园局域网的大学校园IP广播方案设计指南
6.23星期四库作业
3dslam with 16 line lidar and octomap
Detailed explanation of yolov5 training own data set
Deep embedding and alignment of Google | protein sequences
Final review (Day5)
随机推荐
mapbox尝鲜值之云图动画
【无标题】
Configure and use Anaconda environment in pycharm
Making coco datasets
小学校园IP网络广播-基于校园局域网的小学IP数字广播系统设计
联想R7000显卡的拆卸与安装
Differences among bio, NiO and AIO
Source insight License Activation
"C and pointer" - Chapter 13 advanced pointer int * (* (* (*f) () [6]) ()
Redis breakdown penetration avalanche
【无标题】
Redis使用Lua脚本简介
Make your own dataset
Mapbox tasting value cloud animation
Pessimistic lock and optimistic lock of multithreading
【一起上水硕系列】Day 7 内容+Day8
Explanation of several points needing attention in final (tested by the author)
一起上水硕系列】Day 9
Go practice -- gorilla / websocket used by gorilla web Toolkit
Notepad++ wrap by specified character