当前位置:网站首页>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;
}
边栏推荐
- Gan network thought
- 112 stucked keyboard (20 points)
- Detailed explanation of the output end (head) of yolov5 | CSDN creation punch in
- [set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
- (perfect solution) how to set the position of Matplotlib legend freely
- Redis 过期淘汰机制
- DEX net 2.0 for crawl detection
- BIO、NIO、AIO区别
- 动态规划——相关概念,(数塔问题)
- Go language interface learning notes Continued
猜你喜欢

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

Gbase8s unique index and non unique index

Use posture of sudo right raising vulnerability in actual combat (cve-2021-3156)

Simpleitk learning notes

Go practice -- factory mode of design patterns in golang (simple factory, factory method, abstract factory)

Gan network thought

XML Configuration File

Gbase8s composite index (I)

6.23星期四库作业

Disassembly and installation of Lenovo r7000 graphics card
随机推荐
Pessimistic lock and optimistic lock of multithreading
Based on RFC 3986 (unified resource descriptor (URI): general syntax)
获取并监控远程服务器日志
Webapidom get page elements
1115 counting nodes in a BST (30 points)
@Autowired 导致空指针报错 解决方式
JS string and array methods
3dslam with 16 line lidar and octomap
JS function algorithm interview case
Make your own dataset
獲取並監控遠程服務器日志
穀歌 | 蛋白序列的深度嵌入和比對
编译GCC遇到的“pthread.h” not found问题
动态规划——相关概念,(数塔问题)
Obtenir et surveiller les journaux du serveur distant
Explanation of several points needing attention in final (tested by the author)
Basic knowledge of reflection (detailed explanation)
Primary school campus IP network broadcasting - Design of primary school IP digital broadcasting system based on campus LAN
Progressive multi grasp detection using grasp path for rgbd images
ninja: build stopped: subcommand failed.