当前位置:网站首页>AtCoder Beginner Contest 258(A-D)
AtCoder Beginner Contest 258(A-D)
2022-07-03 05:20:00 【.Ashy.】
A - When?
要点:格式化输出时间
#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
注意:
注意搜索的是八个直线方向,而不是每次搜索都搜索八个方向,因为不管怎么搜串长都是一定的,所以我们只从开头最大的数字开始搜
注意读题
#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;
}//右
ans=max(ans,s1);
s1="";
xx=x;
for(int i=1;i<=n;i++)
{
s1+=a[xx][y];
xx--;
if(xx<1) xx=n;
}//左
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;
}//上
ans=max(ans,s1);
s1="";yy=y;
for(int i=1;i<=n;i++)
{
s1+=a[x][yy];
yy--;
if(yy<1) yy=n;
}//下
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;
}//左上
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;
}//右下
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;
}//右上
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;
}//左下
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
思路:
我们用 k 代表移位操作的次数,当 k == n 时相当于没有移动 那么有效移动个数是 k%n ,那么原来的首部就相当于被移动到了 n-k 的位置,要求第b个字母,那就是 n-k+b 位置的字母,当然,这个数也要对 n 取余,如果超过了 n
代表这个数已经被移到前面去了,所以要取余。
一定要注意取余等于 0 的情况对于问题有没有影响!!!!
多带几组例子试试!!!
注意开 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
题意:
n 个阶段,从第一个阶段开始,每进入一个新阶段需要花费 a+b ,而呆在已解锁的阶段只需花费 b ,问 处理 X 次阶段需要花费的最小代价是多少
思路:
我们要找到一个比较小的 b,使得大部分 的处理在 b 上 ,而不是在 a+b 上,使得花费变小,所以这题的思路就是去解锁每一阶段,然后把剩余的处理次数全都处理本阶段也就是花费这个 b ,每个阶段的 b 都试一次,取最小值。
注意数据比较大,开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;
}
边栏推荐
- XML Configuration File
- Principles of BTC cryptography
- [set theory] relationship properties (common relationship properties | relationship properties examples | relationship operation properties)
- [set theory] relation properties (transitivity | transitivity examples | transitivity related theorems)
- Force GCC to compile 32-bit programs on 64 bit platform
- Congratulations to musk and NADELLA on their election as academicians of the American Academy of engineering, and Zhang Hongjiang and Fang daining on their election as foreign academicians
- Differences among bio, NiO and AIO
- Basic knowledge of reflection (detailed explanation)
- Primary school campus IP network broadcasting - Design of primary school IP digital broadcasting system based on campus LAN
- Go language interface learning notes
猜你喜欢
随机推荐
1118 birds in forest (25 points)
BTC-密码学原理
Why should we rewrite hashcode when we rewrite the equals method?
在PyCharm中配置使用Anaconda环境
大学校园IP网络广播-厂家基于校园局域网的大学校园IP广播方案设计指南
Gbase8s unique index and non unique index
Web APIs exclusivity
Yolov5 model construction source code details | CSDN creation punch in
穀歌 | 蛋白序列的深度嵌入和比對
1106 lowest price in supply chain (25 points)
Go practice - gorilla / handlers used by gorilla web Toolkit
leetcode435. Non overlapping interval
About debugging the assignment of pagenum and PageSize of the formal parameter pageweb < T > (i.e. page encapsulation generic) in the controller
JQ style, element operation, effect, filtering method and transformation, event object
Detailed explanation of the output end (head) of yolov5 | CSDN creation punch in
Dynamic programming - related concepts, (tower problem)
1111 online map (30 points)
Brief introduction of realsense d435i imaging principle
"Hands on deep learning" pytorch edition Chapter II exercise
College campus IP network broadcasting - manufacturer's design guide for college campus IP broadcasting scheme based on campus LAN








