当前位置:网站首页>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;
}
边栏推荐
- 联想R7000显卡的拆卸与安装
- 动态规划——相关概念,(数塔问题)
- Redis 入門和數據類型講解
- Making coco datasets
- Webrtc protocol introduction -- an article to understand ice, stun, NAT, turn
- Redis 击穿穿透雪崩
- leetcode452. Detonate the balloon with the minimum number of arrows
- 1106 lowest price in supply chain (25 points)
- Yolov5 input (II) | CSDN creative punch in
- Deploy crawl detection network using tensorrt (I)
猜你喜欢

About debugging the assignment of pagenum and PageSize of the formal parameter pageweb < T > (i.e. page encapsulation generic) in the controller

How to connect the network: Chapter 2 (Part 1): a life cycle of TCP connection | CSDN creation punch in

Deep embedding and alignment of Google | protein sequences

Go practice -- design patterns in golang's singleton

appium1.22. Appium inspector after X version needs to be installed separately

JQ style, element operation, effect, filtering method and transformation, event object

College campus IP network broadcasting - manufacturer's design guide for college campus IP broadcasting scheme based on campus LAN

穀歌 | 蛋白序列的深度嵌入和比對

Disassembly and installation of Lenovo r7000 graphics card

Brief introduction of realsense d435i imaging principle
随机推荐
Promise
Explanation of several points needing attention in final (tested by the author)
Redis expiration elimination mechanism
ROS Compilation Principle
Pan details of deep learning
Class loading mechanism (detailed explanation of the whole process)
Common methods of JS array
Introduction to webrtc protocol -- an article to understand dtls, SRTP, srtcp
1118 birds in forest (25 points)
Obtenir et surveiller les journaux du serveur distant
"Hands on deep learning" pytorch edition Chapter II exercise
The IntelliJ platform completely disables the log4j component
Make your own dataset
Basic knowledge of reflection (detailed explanation)
大学校园IP网络广播-厂家基于校园局域网的大学校园IP广播方案设计指南
Yolov5 input (I) -- mosaic data enhancement | CSDN creative punch in
最大连续子段和(动态规划,递归,递推)
How to connect the network: Chapter 2 (Part 1): a life cycle of TCP connection | CSDN creation punch in
Audio Focus Series: write a demo to understand audio focus and audiomananger
1111 online map (30 points)