当前位置:网站首页>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;
}
边栏推荐
- Win10 install pytullet and test
- Gan network thought
- 1099 build a binary search tree (30 points)
- Go practice -- factory mode of design patterns in golang (simple factory, factory method, abstract factory)
- Force GCC to compile 32-bit programs on 64 bit platform
- Redis 入門和數據類型講解
- Make your own dataset
- Simpleitk learning notes
- Map的扩容机制
- JS dynamic table creation
猜你喜欢

Gbase8s composite index (I)

leetcode406. Rebuild the queue based on height

(完美解决)matplotlib图例(legend)如何自由设置其位置

Celebrate the new year together

Detailed explanation of yolov5 training own data set

(subplots用法)matplotlib如何绘制多个子图(轴域)

Hotel public broadcasting background music - Design of hotel IP network broadcasting system based on Internet +

XML配置文件

@Autowired 导致空指针报错 解决方式

3dslam with 16 line lidar and octomap
随机推荐
Go practice -- design patterns in golang's singleton
Yolov5 network structure + code + application details | CSDN creation punch in
Detailed explanation of yolov5 training own data set
1106 lowest price in supply chain (25 points)
appium1.22.x 版本后的 appium inspector 需单独安装
mysql启动报错:The server quit without updating PID file几种解决办法
Introduction to redis and explanation of data types
SimpleITK学习笔记
[set theory] relation properties (transitivity | transitivity examples | transitivity related theorems)
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
XML配置文件
Yolov5 input (II) | CSDN creative punch in
Go practice -- closures in golang (anonymous functions, closures)
Yolov5 input (I) -- mosaic data enhancement | CSDN creative punch in
1087 all roads lead to Rome (30 points)
配置xml文件的dtd
Basic knowledge of reflection (detailed explanation)
Pessimistic lock and optimistic lock of multithreading
Redis Introduction et explication des types de données
1118 birds in forest (25 points)