
白给题
#include <bits/stdc++.h> using namespace std; int main () { string s; int num; cin >> num; while(num--) { cin >> s; cout << s.size() << endl; } }

白给题2用锤子二分
#include <bits/stdc++.h>
using namespace std;
int main () {
int t;
cin >> t;
while(t--) {
int x;
cin >> x;
int n = (-1.0 + sqrt(1 + 8 * x)) / 2.0;
if((1 + n) * n / 2 == x) {
cout << n << endl;
} else if((n + 2) * (n + 1) / 2 - x == 1) {
cout << n + 2 << endl;
} else {
cout << n + 1 << endl;
}
}
}

简单的博弈分析罢了。不断进行状态转移(反正消耗能量也就1,如果消耗多了可能还涉及DP)对于后手来说最理想的状态就是获得所有能量的分,这是一定可以做到的,前面的球不接就行了。对于先手来说可以把自己球全部打完,当轮到最后一个球时,后手开始接盘。
#include <bits/stdc++.h>
using namespace std;
int main () {
int t;
cin >> t;
while(t--) {
int x, y;
cin >> x >> y;
cout << x - 1 << " " << y << endl;
}
}

遍历一下数组记录一下变化代价,遇到x<v[i]才进行更新x。然后出现unorder的情况。把此状态的x和小的数swap,然后加上付出的代价即可。有点儿类似于DP的思想但我这种方法只是通过代价考虑。
#include <bits/stdc++.h>
using namespace std;
int main () {
int t;
cin >> t;
while(t--) {
int n, x;
cin >> n >> x;
std::vector<int> v(n + 1);
for(int i = 1; i <= n; ++i){
cin >> v[i];
}
bool ok = 0;
int num = 0;
int gap = 1;
for(int i = 2; i <= n; ++i) {
if(v[i] < v[i - 1]) {
if(v[i] < x) {
ok = 1;
break;
}
num += gap;
swap(x, v[i - 1]);
gap = 1;
}
if(x < v[i - 1]) {
gap++;
x = v[i - 1];
}
}
if(ok) {
cout << -1 << endl;
} else {
cout << num << endl;
}
}
}

next_permutation用于暴力所有情况,首先算出最朴素的情况,然后nw = abs(y[1] - y[2]) + abs(y[3] - y[4]) + abs(x[1] - x[3]) + abs(x[2] - x[4]);不能得到正方形的话,需要进行添加
#include <bits/stdc++.h>
using namespace std;
#define int long long
int x[5], y[5], xx[5], yy[5], c[5], T;
signed main () {
scanf("%lld", &T);
while(T--) {
int nw, ans = 2e9, xl, xr, yl, yr;
for(int i = 1; i <= 4; ++i) {
scanf("%lld%lld", &xx[i], &yy[i]);
c[i] = i;
}
do{
for(int i = 1; i <= 4; ++i) {
x[i] = xx[c[i]], y[i] = yy[c[i]];
//cout << c[i] << " ";
}
//cout << endl;
nw = abs(y[1] - y[2]) + + abs(x[2] - x[4]) + abs(y[4] - y[3]) + abs(x[3] - x[1]) ;
yl = min(y[1], y[2]) - max(y[3], y[4]);
yr = max(y[1], y[2]) - min(y[3], y[4]);
xl = min(x[2], x[4]) - max(x[1], x[3]);
xr = max(x[2], x[4]) - min(x[1], x[3]);
//cout << yl << " " << yr << " " << xl << " " << xr << endl;
if(xr < yl) nw += (yl - xr) * 2;
if(xl > yr) nw += (xl - yr) * 2;
ans = min(ans, nw);
}while(next_permutation(c + 1, c + 5));
printf("%lld
", ans);
}
return 0;
}