A. Dislike of Threes
简单的水题,预处理即可
AC_CODE
#include <bits/stdc++.h>
using namespace std;
template < typename T >
inline void read(T &x)
{
x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)){f ^= !(ch ^ 45);ch=getchar();}
while(isdigit(ch)) x= (x<<1)+(x<<3)+(ch&15),ch=getchar();
x = f ? -x : x;
}
const int N = 1e5 + 10;
int a[N];
void solve() {
int n; read(n);
printf("%d\n", a[n]);
}
signed main()
{
int p = 1;
for(int i = 1; p < 1110; i ++ ) {
if(i % 3 == 0 || i % 10 == 3) continue;
a[p ++ ] = i;
}
int T = 1;cin >> T;
while(T -- ) solve();
return 0;
}
B. Who's Opposite?
sb题
找到这个环的中间位置,然后判断三个数字是否在环外即可
AC_CODE
#include <bits/stdc++.h>
using namespace std;
template < typename T >
inline void read(T &x)
{
x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)){f ^= !(ch ^ 45);ch=getchar();}
while(isdigit(ch)) x= (x<<1)+(x<<3)+(ch&15),ch=getchar();
x = f ? -x : x;
}
void solve() {
int a, b, c;
read(a); read(b); read(c);
if(a > b) swap(a, b);
int res = b - a;
int len = res * 2;
if(b > len || c > len) {
puts("-1");
return;
}
int ans = c + res;
if(ans > 2 * res) ans %= (2 * res);
printf("%d\n",ans);
}
signed main()
{
int T = 1;cin >> T;
while(T -- ) solve();
return 0;
}
C - Infinity Table
预处理出所有的平方数
- 首先判断这个数字是在哪一行or哪一列 (开方向上取整即可) 假设这个数字是idx
- 其次判断这个数字是在列还是行
- 如果是列 则输出 n - \(idx^2\) 如果是行则输出 \((idx+1)^2\) - n + 1
#include <bits/stdc++.h>
using namespace std;
template < typename T >
inline void read(T &x)
{
x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)){f ^= !(ch ^ 45);ch=getchar();}
while(isdigit(ch)) x= (x<<1)+(x<<3)+(ch&15),ch=getchar();
x = f ? -x : x;
}
const int N = 1e5 + 10;
int a[N];
int p = 1;
void solve() {
int n; read(n);
int idx = lower_bound(a + 1, a + 1 + p, n) - a;
int res = n - a[idx - 1];
if(res <= idx) {
printf("%d %d\n", res, idx);
return;
}
res = a[idx] - n;
printf("%d %d\n", idx, res + 1);
}
signed main()
{
for(int i = 1; i <= INF / i; i ++ ) {
a[p ++] = i * i;
}
int T = 1;cin >> T;
while(T -- ) solve();
return 0;
}
D - Make a Power of Two
预处理出所有的 \(2^n\)
暴力枚举从原来的数字操作到 \(2^n\) 所需的最小操作次数 取最小值
最小操作次数判断时候,即是判断重复子序列长度
AC_CODE
//#pragma GCC optimize (2)
//#pragma G++ optimize (2)
#include <bits/stdc++.h>
using namespace std;
template < typename T >
inline void read(T &x)
{
x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)){f ^= !(ch ^ 45);ch=getchar();}
while(isdigit(ch)) x= (x<<1)+(x<<3)+(ch&15),ch=getchar();
x = f ? -x : x;
}
string a[63];
void solve() {
string x; cin >> x;
int ans = INF;
int p = x.size();
for(int i = 0; i < 63; i ++ ) {
int len = a[i].size(), tt = 0;
for(int j = 0; j < p; j ++ ) {
if(tt < len && x[j] == a[i][tt]) tt ++;
}
int r = len - tt + p - tt;
ans = min(ans, r);
if(ans > r) {
cout << i << endl;
ans = r;
}
}
printf("%d\n", ans);
}
signed main()
{
for(int i = 0; i < 63; i ++ ) {
LL p = (1LL << i);
a[i] = to_string(p);
}
int T = 1;cin >> T;
while(T -- ) solve();
return 0;
}