Compare commits
3
Commits
57392df977
...
fa496ca42e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa496ca42e | ||
|
|
890d0f8f1b | ||
|
|
a31571cb3c |
+33
@@ -0,0 +1,33 @@
|
|||||||
|
#include<bits/stdc++.h>
|
||||||
|
using namespace std;
|
||||||
|
int t,k;
|
||||||
|
int n;
|
||||||
|
char s[200005];
|
||||||
|
int main(){
|
||||||
|
scanf("%d%d",&t,&k);
|
||||||
|
while(t--){
|
||||||
|
scanf("%d%s",&n,s);
|
||||||
|
bool flag=0;
|
||||||
|
vector<char> ans;
|
||||||
|
for(int i=n-1;i>=0;--i){
|
||||||
|
if((s[i]=='O'&&!flag) || (s[i]=='M' &&flag)){
|
||||||
|
ans.push_back('O');
|
||||||
|
flag=!flag;
|
||||||
|
}else{
|
||||||
|
ans.push_back('M');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
puts("YES");
|
||||||
|
if(k==1){
|
||||||
|
for(int i=n-1;i>=0;--i){
|
||||||
|
putchar(ans[i]);
|
||||||
|
}
|
||||||
|
puts("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
MOO
|
||||||
|
MOO
|
||||||
|
*/
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
#include<bits/stdc++.h>
|
||||||
|
using namespace std;
|
||||||
|
int n,k;
|
||||||
|
int cs[25][25][25];
|
||||||
|
int calc(int now){
|
||||||
|
int ans=0;
|
||||||
|
for(int i=0;i<n;i++){
|
||||||
|
if(!(now&(1<<i))) continue;
|
||||||
|
for(int j=0;j<n;j++){
|
||||||
|
if((now&(1<<j))) continue;
|
||||||
|
for(int k=j;k<n;k++){
|
||||||
|
if(!(now&(1<<k))){
|
||||||
|
ans+=cs[i][j][k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
int main(){
|
||||||
|
scanf("%d%d",&n,&k);
|
||||||
|
for(int i=1;i<=k;++i){
|
||||||
|
int x,y,z;
|
||||||
|
scanf("%d%d%d",&x,&y,&z);
|
||||||
|
x--,y--,z--;
|
||||||
|
if(y>z) swap(y,z);
|
||||||
|
cs[x][y][z]++;
|
||||||
|
}
|
||||||
|
int maxans=0,count=0;
|
||||||
|
for(int i=0;i<=(1<<n)-1;i++){ // 二进制表示棋盘
|
||||||
|
int ci=calc(i);
|
||||||
|
if(ci>maxans) count=1, maxans=ci;
|
||||||
|
else if(ci==maxans) count++;
|
||||||
|
}
|
||||||
|
printf("%d %d\n",maxans,count);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
using namespace std;
|
||||||
|
typedef long long ll;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int N, Q;
|
||||||
|
scanf("%d %d", &N, &Q);
|
||||||
|
vector<ll> a(N + 1);
|
||||||
|
for (int i = 1; i <= N; ++i) {
|
||||||
|
scanf("%lld", &a[i]);
|
||||||
|
}
|
||||||
|
const int MAXI = 31;
|
||||||
|
vector<ll> dp(MAXI + 2, 0);
|
||||||
|
dp[1] = a[1];
|
||||||
|
for (int i = 2; i <= MAXI; ++i) {
|
||||||
|
if (i <= N)
|
||||||
|
dp[i] = min(a[i], 2 * dp[i - 1]);
|
||||||
|
else
|
||||||
|
dp[i] = 2 * dp[i - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
while (Q--) {
|
||||||
|
ll x;
|
||||||
|
scanf("%lld", &x);
|
||||||
|
ll ans = LLONG_MAX;
|
||||||
|
ll cur_cost = 0;
|
||||||
|
bool tight = true;
|
||||||
|
for (int i = 30; i >= 0; --i) {
|
||||||
|
if (tight) {
|
||||||
|
if ((x >> i) & 1LL) {
|
||||||
|
cur_cost += dp[i + 1];
|
||||||
|
} else {
|
||||||
|
ans = min(ans, cur_cost + dp[i + 1]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ans = min(ans, cur_cost);
|
||||||
|
printf("%lld\n", ans);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user