AtCoder Beginner Contest 275
A - Find Takahashi
找到序列中最高的数存在的位置
#include<bits/stdc++.h>
using namespace std;
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;
}
int32_t main() {
int n = read() , res = INT_MIN , id = 0;
for( int i = 1 , x ; i <= n ; i ++ ){
x = read();
if( x > res ) res = x , id = i;
}
cout << id << "\n";
return 0;
}
B - ABC-DEF
注意乘法可能会爆精度,所以注意取模
#include<bits/stdc++.h>
#define int long long
using namespace std;
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;
}
const int mod = 998244353;
int32_t main() {
int a = read() % mod , b = read() % mod , c = read() % mod , d = read() % mod ;
int e = read() % mod , f = read() % mod;
a = a * b % mod * c % mod;
d = d * e % mod * f % mod;
cout << ( ( a - d ) % mod + mod ) % mod;
return 0;
}
C - Counting Squares
#
代表棋子,问由棋子做顶点可以组合出多少个正方形。
首先先用 dfs 枚举出四个棋子。如果四个点两两之间的距离只有两种情况,那么该矩形就是一个正方形
#include<bits/stdc++.h>
#define int long long
using namespace std;
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;
}
const int mod = 998244353;
int res;
vector< pair<int,int> > p , t;
int dis( int ax , int ay , int bx , int by ){
return ( ax - bx ) * ( ax - bx ) + ( ay - by ) * ( ay - by );
}
void dfs( int x ){
if( t.size() == 4 ){
set<int> s;
for( int i = 0 ; i < 4 ; i ++ )
for( int j = 0 ; j < i ; j ++ )
s.insert( dis( t[i].first , t[i].second , t[j].first , t[j].second ) );
if( s.size() == 2 ) res ++;
return;
}
for( int i = x ; i < p.size() ; i ++ )
t.push_back( p[i] ) , dfs( i+1 ) , t.pop_back();
return;
}
int32_t main() {
string s[10];
for( int i = 0 ; i < 9 ; i ++ )
cin >> s[i];
for( int i = 0 ; i < 9 ; i ++ )
for( int j = 0 ; j < 9 ; j ++ )
if( s[i][j] == '#' ) p.push_back( { i , j } );
dfs( 0 );
cout << res << "\n";
return 0;
}
D - Yet Another Recursive Function
这道题看似数据范围很大,但是因为是除法的问题,所以一共不会使用超过 100 个数组。发现这点的话就是一个简单的记忆化搜索,记忆化用个 map 存一下就好
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int> f;
int F( int x ){
if( f.count(x) ) return f[x];
return f[x] = F( x / 2 ) + F( x / 3 );
}
int32_t main() {
int n;
cin >> n;
f[0] = 1;
cout << F(n) << "\n";
return 0;
}