# A

#include <bits/stdc++.h>
const int N = 100050;
const int INF = 1 << 30;
typedef long long ll;
using namespace std;
int n, x, num, ans[N];
int main() {
cin >> n;
for(int i = 1; num <= 1000; i++) {
if(i % 10 == 3 || i % 3 == 0)
continue;
ans[++num] = i;
}
for(int i = 1; i <= n; i++) {
cin >> x;
cout << ans[x] << endl;
}
return 0;
}


# B

#include <bits/stdc++.h>
const int N = 100050;
const int INF = 1 << 30;
typedef long long ll;
using namespace std;
int t, a, b, c, d;
int main() {
cin >> t;
while(t--) {
cin >> a >> b >> c;
d = abs(a - b);
if(abs(a - b) == 1 || min(a, b) > abs(a - b) || c > 2 * d) {
cout << "-1" << endl;
continue;
}
c <= d ? cout << c + d << endl : cout << c - d << endl;
}
return 0;
}


# C

#include <bits/stdc++.h>
const int N = 100050;
const int INF = 1 << 30;
typedef long long ll;
using namespace std;
int t, x, n;
int main() {
cin >> t;
while(t--) {
cin >> x;
for(int i = 1; i <= 32000; i++) {
if(i * i >= x) {
n = i;
break;
}
}
if(x <= n * n - n + 1)
cout << x - (n - 1) * (n - 1) << " " << n << endl;
else
cout << n << " " << n - (x - (n * n - n + 1)) << endl;
}
return 0;
}


# D

## 思路

#include <bits/stdc++.h>
const int N = 100;
const int INF = 1 << 30;
typedef long long ll;
using namespace std;
int k, ans;
ll bin[N];
string s;
int calc(ll x) {
string t = "";
while(x) {
t += (x % 10) + '0';
x /= 10;
}
reverse(t.begin(), t.end());
int cnt = 0, j = 0, l = 0;
while(j < s.length() && l < t.length()){
if(s[j] == t[l]) {
++cnt;
j++;
l++;
}
else j++;
}
return s.length() + t.length() - cnt * 2;
}
int main() {
ios::sync_with_stdio(false);
cin >> k;
bin[0] = 1;
for(int i = 1; i <= 62; i++) bin[i] = bin[i - 1] * 2;
while(k--) {
ans = INF;
cin >> s;
for(int i = 0; i <= 62; i++) ans = min(ans, calc(bin[i]));
cout << ans << endl;
}
return 0;
}


# F1

## 思路

$k=1$，则可以通过枚举找到答案。

$k=2$，我们可以枚举确定答案是由哪两个数字组成，同时按贪心思路构造出较小的答案，进行统计。很难想。

#include <bits/stdc++.h>
using namespace std;
int t, k;
set<char> o;
string s;
string calc(char x) {
string y = "";
for(int i = 0; i < s.length(); i++) y += x;
return y;
}
void solve1() {
for(char i = '0'; i <= '9'; i++) {
string t = calc(i);
if(t > s) {
cout << t << endl;
return ;
}
}
}
void solve2() {
string t = calc('9');
for(char i = '0'; i <= '9'; i++) {
for(char j = i + 1; j <= '9'; j++) {
for(int l = 0; l < s.length(); l++) {
if(s[l] < j) {
string g = s;
g[l] < i ? g[l] = i : g[l] = j;
for(int p = l + 1; p < g.length(); p++) g[p] = i;
if(t > g) t = g;
}
if(s[l] != i && s[l] != j) break;
}
}
}
cout << t << endl;
}
int main() {
ios::sync_with_stdio(false);
cin >> t;
while(t--) {
o.clear();
cin >> s >> k;
for(int i = 0; i < s.length(); i++) o.insert(s[i]);
if(o.size() <= k) {
cout << s << endl;
continue;
}
k == 1 ? solve1() : solve2();
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t, k;
set<char> o;
string s;
string calc(char x) {
string y = "";
for(int i = 0; i < s.length(); i++) y += x;
return y;
}
void solve1() {
for(char i = '0'; i <= '9'; i++) {
string t = calc(i);
if(t > s) {
cout << t << endl;
return ;
}
}
}
void dfs(int step, char t1, char t2, string &t, string p) {
//cout << t << " " << p << endl;
if(step == 2 && p == "0")
return ;
if(step != 1 && p[0] < s[0])
return ;
if(step == s.length() + 1) {
if(p < t && p > s) {
t = p;
return ;
}
return ;
}
string last = p;
dfs(step + 1, t1, t2, t, p + t1);
p = last;
dfs(step + 1, t1, t2, t, p + t2);
p = last;
}
void solve2() {
string t = "", p = "";
t = calc('9');
for(char i = '0'; i <= '9'; i++) {
for(char j = '0'; j <= '9'; j++) {
if(i == j)
continue;
//	cout << *it1 << " " << *it2 << endl;
dfs(1, i, j, t, p);
}
}
cout << t << endl;
}
int main() {
ios::sync_with_stdio(false);
cin >> t;
while(t--) {
o.clear();
cin >> s >> k;
for(int i = 0; i < s.length(); i++) o.insert(s[i]);
if(o.size() <= k) {
cout << s << endl;
continue;
}
k == 1 ? solve1() : solve2();
}
return 0;
}

posted @ 2021-08-21 20:09  BeyondLimits  阅读(21)  评论(3编辑  收藏  举报