AtCoder Beginner Contest 257
A - A to Z String 2
签到
#include <bits/stdc++.h>
using namespace std;
int read(){
int x = 0 , ch = getchar();
while( ch < '0' || ch > '9' ) ch = getchar();
while( ch >= '0' && ch <= '9' ) x = ( x << 3 ) + ( x << 1 ) + ch - '0' , ch = getchar();
return x;
}
int main()
{
int n , x;
cin >> n >> x;
for( char i = 'A' ; i <= 'Z' ; i ++ )
{
if( x > n ) x -= n;
else printf("%c\n" , i ) , exit(0);
}
}
B - 1D Pawn
判断一下被移动的时候和下一位相邻,是否是边界。然后移动就好了
#include <bits/stdc++.h>
using namespace std;
int n , a[205] , k , q;
int read(){
int x = 0 , ch = getchar();
while( ch < '0' || ch > '9' ) ch = getchar();
while( ch >= '0' && ch <= '9' ) x = ( x << 3 ) + ( x << 1 ) + ch - '0' , ch = getchar();
return x;
}
int main()
{
cin >> n >> k >> q;
for( int i = 1 ; i <= k ; i ++ )
cin >> a[i];
for( int i = 1 , x ; i <= q ; i ++ )
{
cin >> x;
if( a[x] == n ) continue;
if( a[x] + 1 == a[x+1] ) continue;
a[x] ++;
}
for( int i = 1 ; i <= k ; i ++ )
cout << a[i] << " ";
cout << endl;
}
C - Robot Takahashi
这道题的意思是机器人会单纯的按照体重把人分为大人和儿童。现在给出 n 个人的体重和是大人还是小孩。然后问如何界定标准最准确。
首先要知道的是,标准界定在人与人之间还是界定在人是没有影响的,所以我们统计全部的大人数量,然后把所有人排序,并界定为大人,然后依次把每个人变成儿童,在枚举的过程中找到最准确的答案
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int n , sum , cnt , ans;
pair< int , int > w[N];
string s;
int read(){
int x = 0 , ch = getchar();
while( ch < '0' || ch > '9' ) ch = getchar();
while( ch >= '0' && ch <= '9' ) x = ( x << 3 ) + ( x << 1 ) + ch - '0' , ch = getchar();
return x;
}
int main()
{
n = read();
cin >> s;
for( auto it : s )
sum += it == '1';
for( int x , i = 1 ; i <= n ; i ++ )
w[i].first = read() , w[i].second = s[i-1] == '1';
sort( w + 1 , w + 1 + n );
ans = sum;
for( int i = 1 ; i <= n ; i ++ ){
if( w[i].second == 0 ) cnt ++;
else sum --;
if( w[i].first == w[i+1].first ) continue;
ans = max( ans , cnt + sum );
}
cout << ans << endl;
}
E - Addition and Multiplication 2
这道题其实很简单,先用最便宜的占位,如果有多个最便宜的就用他们之中最大一个,然后从高位开始把每一位尽可能的变大就好了。
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
int n , ans[N] , c[15] , t , p , m ;
int main()
{
cin >> n;
for( int i = 1 ; i <= 9 ; i ++ )
cin >> c[i];
t = c[9] , p = 9;
for( int i = 8 ; i >= 1 ; i -- )
if( c[i] < t ) t = c[i] , p = i;
m = n / t , n %= t;
for( int i = 1 ; i <= 9 ; i ++ ) c[i] -= t;
for( int i = 1 ; i <= m ; i ++ )
{
if( n == 0 ) {
cout << p;
continue;
}
for( int i = 9 ; i >= p ; i -- )
if( c[i] <= n ) {
cout << i;
n -= c[i];
break;
}
}
}
D - Jumping Takahashi 2
这道题我读错了题目,S
值在跳的过程中是不会变化的,题目说跳增加S
指的是开始时原地跳跃
知道了正确的题意就简单了,我们只要二分答案就好了,判断,我这里采用的是比较笨的方法,就是暴力的跑 dfs,但是也有简单方法就是Floyd 就好
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 205 , inf = 5e9;
int n ,sx[N] , sy[N] , sp[N];
vector< int > e[N];
bitset<N> vis;
int read() {
int x = 0, f = 1, ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') f = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return x * f;
}
int getdist( int u , int v ){
return abs( sx[u] - sx[v] ) + abs( sy[u] - sy[v] );
}
void dfs( int u ){
if( vis[u] ) return;
vis[u] = 1;
for( auto v : e[u] )
dfs( v );
return;
}
bool pending( int v ){
for( int i = 1 ; i <= n ; i ++ ) e[i].clear();
vis.reset();
for( int i = 1 ; i <= n ; i ++ )
for( int j = 1 ; j <= n ; j ++ )
if( i == j ) continue;
else {
if( getdist( i , j ) <= sp[i] * v ) e[i].push_back(j);
}
for( int i = 1 ; i <= n ; i ++ ){
vis.reset();
dfs( i );
bool flag = 1;
for( int j = 1 ; j <= n ; j ++ )
if( !vis[j] ) flag = 0;
if( flag ) return 1;
}
return 0;
}
int32_t main() {
n = read();
for( int i = 1 ; i <= n ; i ++ )
sx[i] = read() , sy[i] = read() , sp[i] = read();
int l = 1 , r = inf , mid , ans ;
while( l <= r ){
mid = ( l + r ) >> 1;
if( pending( mid ) ) ans = mid , r = mid - 1 ;
else l = mid + 1;
}
cout << ans << endl;
}