题目网址:
B Boss Battle
思维结论题 n<=3输出1,其余输出n-2即可
原理:顺时针或逆时针转圈,每次Boss移动+1,炸弹覆盖移动可以+2
D Dinguish
map+乘法原理+补集统计
#include<bits/stdc++.h>
#define maxn 30
#define maxm 100010
#define ll long long
using namespace std;
string s[maxn], dic[maxm][5];
map<string, int> M,M1;
map<string,string> trans;
int n, m, a[maxn];
ll ans1,ans;
int main() {
cin >> n;
for (int i = 1; i <= n; i++)cin >> s[i];
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> dic[i][1] >> dic[i][2] >> dic[i][3];
M[dic[i][1]]++;
trans[dic[i][1]]=dic[i][2];
//cout<<dic[i][3]<<",,"<<endl;
if(dic[i][3]=="correct"){
M1[dic[i][1]]++;
}
}
ans1=1;ans=1;
for (int i = 1; i <= n; i++){
ans1*=M1[s[i]];
ans*=M[s[i]];
}
if(ans==1){
for(int i=1;i<=n;i++)cout<<trans[s[i]]<<" ";
cout<<endl;
if(ans1==0)cout<<"incorrect";
else cout<<"correct";
}
else{
ans-=ans1;
cout<<ans1<<" correct"<<endl;
cout<<ans<<" incorrect";
}
return 0;
}H Highscore
暴力+分类讨论(暴力范围,技巧)
#include<bits/stdc++.h>
#define maxn 4200
#define ll long long
using namespace std;
ll t, a, b, c, d, ans;
ll maxx(ll x, ll y) {
return x > y ? x : y;
}
ll minn(ll x, ll y) {
return x < y ? x : y;
}
ll sqr(ll x) {
return x * x;
}
bool cmp(ll x, ll y) {
return x > y;
}
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d%d%d", &a, &b, &c, &d);
ll aa[5];
aa[1] = a;
aa[2] = b;
aa[3] = c;
sort(aa + 1, aa + 4, cmp);
ans = 0;
if (d <= 9000) {
for (int i = 0; i <= d; i++) {
for (int j = 0; j <= d - i; j++) {
ans = maxx(ans, sqr(a + i) + sqr(b + j) + sqr(c + d - i - j) +
minn(a + i, minn(b + j, c + d - i - j)) * 7);
}
}
} else {
ans = sqr(aa[1] + d) + sqr(aa[2]) + sqr(aa[3]) + 7 * aa[3];
}
cout << ans << endl;
}
return 0;
}J Juggling Troupe
思维题+stl库
stl库注意!如果要对set在红黑树上二分,需要些M.lower_bound,而不是放入迭代器直接调用的lowerbound!
直接调用的lowerbound一般给数组用!是一个内置的二分,传两个迭代器进去无法找mid,所以无法二分,复杂度退化为线性。
string用char数组可替换!
思路:
找规律。发现如果只有一个2时,设2的位置为i,i的左边第一个0的位置为L,i右边第一个0的位置为R,最终的状态为:位置L,R变为1,位置L+R−i变为0,[L,R]的其它位置变为1。
又发现每个2是独立的,即每个2可以不同时扔球,可以分开处理。所以最终的解法就是按照只有一个2的解法解决每个2即可。
不必实时更改string,可以现在set内全部处理完毕最后再改string!
#include<bits/stdc++.h>
#define maxn 1000010
#define ll long long
using namespace std;
char s[maxn];
int len, n;
typedef set<int>::iterator IT;
set<int> M;
int main() {
scanf("%s",s+1);
len = strlen(s+1);
M.insert(0);
for (int i = 1; i <= len; i++) {
if (s[i] == '0')M.insert(i);
}
M.insert(len+1);
for (int i = 1; i <= len; i++) {
if (s[i] == '2') {
set<int>::iterator r1,r,l;
r1 = M.lower_bound(i);
r = r1;
l = r1.operator--();
if (*l >0) {
M.erase(l);
}
if (*r <= len) {
M.erase(r);
}
//cout<<*l<<","<<*r<<endl;
int ql = *l + *r - i;
M.insert(ql);
}
}
for (int i = 1; i <= len; i++)s[i] = '1';
for (auto i = M.begin(); i != M.end(); i++) {
s[*i] = '0';
}
for(int i=1;i<=len;i++)putchar(s[i]);
return 0;
}