A活着的证据
题目
思路
恶心的细节题.
保证位数最大贪心即可,居然罚了三次时
代码
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int read() {
int re = 0;
char c = getchar();
bool negt = false;
while(c < '0' || c > '9')
negt |= (c == '-') , c = getchar();
while(c >= '0' && c <= '9')
re = (re << 1) + (re << 3) + c - '0' ,c = getchar();
return negt ? -re : re;
}
char ans[5000010];
int main() {
int T = read();
while(T--) {
int v = read() , I = read() , len = read();
int maxlen = min(len , v + I);
int j = -1;
while((v > 0 || I > 0) && j < maxlen - 1) {
++j;
if(v >= 1 && I >= 3 && j + v + I - 4 + 1 >= maxlen) {
--v , I -= 3;
ans[j] = '8';
continue;
}
if(v >= 1 && I >= 2 && j + v + I - 3 + 1 >= maxlen) {
--v , I -= 2;
ans[j] = '7';
continue;
}
if(v >= 1 && I >= 1 && j + v + I - 2 + 1 >= maxlen) {
--v , I -= 1;
ans[j] = '6';
continue;
}
if(v >= 1) {
--v;
ans[j] = '5';
continue;
}
if(I >= 3 && j + I - 3 + 1 >= maxlen) {
I -= 3;
ans[j] = '3';
continue;
}
if(I >= 2 && j + I - 2 + 1 >= maxlen) {
I -= 2;
ans[j] = '2';
continue;
}
I -= 1;
ans[j] = '1';
continue;
}
ans[j + 1] = 0;
puts(ans);
}
return 0;
}
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int read() {
int re = 0;
char c = getchar();
bool negt = false;
while(c < '0' || c > '9')
negt |= (c == '-') , c = getchar();
while(c >= '0' && c <= '9')
re = (re << 1) + (re << 3) + c - '0' ,c = getchar();
return negt ? -re : re;
}
char ans[5000010];
int main() {
int T = read();
while(T--) {
int v = read() , I = read() , len = read();
for(int i = 0 ; i <= len ; i++) ans[i] = 0;
for(int j = 0 ; j < len ; j++) {
if(v > 0)
ans[j] = '5' , --v;
else if(I > 0)
ans[j] = '1' , --I;
}
for(int j = 0 ; j < len ; j++) {
if(ans[j] == '5') {
if(I >= 3)
ans[j] += 3 , I -= 3;
else if(I >= 2)
ans[j] += 2 , I -= 2;
else if(I >= 1)
ans[j] += 1 , I -= 1;
} else {
if(I >= 2)
ans[j] += 2 , I -= 2;
else if(I >= 1)
ans[j] += 1 , I -= 1;
}
}
puts(ans);
}
return 0;
}
B寻寻觅觅寻不到
题目
思路
字符串哈希模板
代码
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int N = 300010;
char m[N] , c[N];
int n;
int k;
typedef unsigned long long lint;
lint Pow(lint a , int p) {
lint res = 1;
while(p) {
if(p & 1)
res = res * a;
a = a * a;
p >>= 1;
}
return res;
}
lint val[N];
int main() {
int T;
scanf("%d" , &T);
while(T--) {
scanf("%s %s %d" , &m , &c , &k);
int len1 = strlen(m) , len2 = strlen(c);
if(len1 != len2) {
puts("NO");
continue;
}
lint ha_c = 0;
for(int i = 0 ; i < len2 ; i++)
ha_c = ha_c * 131 + (lint)c[i];
val[0] = m[0];
for(int i = 1 ; i < len1 ; i++)
val[i] = val[i - 1] * 131 + (lint)m[i];
bool flag = false;
for(int i = 0 ; i + k - 1 < len1 ; i++) {
if(ha_c == val[i - 1] * Pow(131 , len1 - i ) + (val[len1 - 1] - val[i + k - 1] * Pow(131 , len1 - i -k)) * Pow(131 , k) + (val[i + k - 1] - val[i - 1] * Pow(131 , k))) {
flag = true;
break;
}
}
puts(flag ? "YES" : "NO");
}
return 0;
}
C踩不出足迹
题目
思路
大声说出来,同或是什么东西:
又因为\(a\oplus\lnot b=\lnot(a\oplus b)\).
所以,当\(m\)个数用的是同或运算时,相当于\(a_1\oplus a_2\oplus \cdots \oplus a_n\)取\(m\)次反,又相当于取\(m\bmod 2\)次反,然后做完了.
代码
#include <iostream>
#include <cstdio>
using namespace std;
#define BruteForce 0
#define int ull
typedef unsigned long long ull;
ull read() {
ull re = 0;
char c = getchar();
bool negt = false;
while(c < '0' || c > '9')
negt |= (c == '-') , c = getchar();
while(c >= '0' && c <= '9')
re = (re << 1) + (re << 3) + c - '0' ,c = getchar();
return negt ? -re : re;
}
const int N = 1000010;
int n , k;
ull a[N];
#if BruteForce
ull ans;
void dfs(int x , ull now) {
if(x == n + 1) {
now = now & (1ull << k) - 1;
if(now > ans)
ans = now;
return;
}
dfs(x + 1 , now ^ a[x]);
dfs(x + 1 , now ^ a[x] ^ (1ull << k) - 1);
}
void print2(ull x) {
char s[110];
for(int i = k ; i >= 0 ; i--)
s[i] = '0' + (x & 1) , x >>= 1;
puts(s);
}
#endif
signed main() {
n = read() , k = read();
for(int i = 1 ; i <= n ; i++)
a[i] = read();
#if BruteForce
dfs(2 , a[1]);
cout << ans;
#else
ull sum = a[1];
for(int i = 2 ; i <= n ; i++)
sum ^= a[i];
if(k < 64)
cout << max(sum , sum ^ ((1ull << k) - 1) );
else
printf("%llu" , max(sum , sum ^ (ull)-1 ));
#endif
return 0;
}
D~F
到这里就没有再做了,听说D是什么克鲁斯卡尔重构树,没学,感觉也没必要,然后就结束了.