当前位置:网站首页>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
- Redis Introduction et explication des types de données
- 1119 pre- and post order traversals (30 points)
- Principles of BTC cryptography
- Deep embedding and alignment of Google | protein sequences
- [backtrader source code analysis 4] use Python to rewrite the first function of backtrader: time2num, which improves the efficiency by 2.2 times
- 1114 family property (25 points)
- (perfect solution) how to set the position of Matplotlib legend freely
- appium1.22.x 版本後的 appium inspector 需單獨安裝
- ROS Compilation Principle
猜你喜欢
Intégration profonde et alignement des séquences de protéines Google
appium1.22.x 版本後的 appium inspector 需單獨安裝
How to connect the network: Chapter 1 CSDN creation punch in
@Autowired 导致空指针报错 解决方式
Celebrate the new year together
【批处理DOS-CMD命令-汇总和小结】-CMD窗口的设置与操作命令-关闭cmd窗口、退出cmd环境(exit、exit /b、goto :eof)
联想R7000显卡的拆卸与安装
6.23星期四库作业
Skip table: principle introduction, advantages and disadvantages of skiplist
Technical analysis of qianyuantong multi card aggregation router
随机推荐
1119 pre- and post order traversals (30 points)
微服务常见面试题
6.23星期四库作业
Common methods of JS array
Webapidom get page elements
[batch dos-cmd command - summary and summary] - CMD window setting and operation command - close CMD window and exit CMD environment (exit, exit /b, goto: EOF)
JS scope
Web APIs exclusivity
Appium 1.22. L'Inspecteur appium après la version X doit être installé séparément
Robot capture experiment demonstration video
leetcode452. Detonate the balloon with the minimum number of arrows
Audio Focus Series: write a demo to understand audio focus and audiomananger
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
1099 build a binary search tree (30 points)
Go practice -- gorilla/rpc (gorilla/rpc/json) used by gorilla web Toolkit
Botu uses peek and poke for IO mapping
[set theory] relationship properties (common relationship properties | relationship properties examples | relationship operation properties)
Objects. Requirenonnull method description
1094 the largest generation (25 points)
[set theory] relation properties (transitivity | transitivity examples | transitivity related theorems)