A. Generous Kefa
如果有字母的个数大于k则NO
#includeusing namespace std;int arr[28],n,k;string str;int main(){ cin>>n>>k; cin>>str; for(int i = 0;i k )return 0*printf("NO"); } printf("YES"); return 0;}
B. Godsend
如果和为奇数first直接赢,如果没有奇数second直接赢,有的话拿走奇数个奇数
数组中有奇数个奇数,second无论怎么拿都是first赢
#includeusing namespace std;int arr[1000100],n,sum,even,odd;int main(){ cin>>n; for(int i = 0;i
C. Leha and Function
数论水平太差……总之b中最小数配a中最大数找规律过的,代码就不贴了
D. Leha and another game about graph
先判不行的情况,如果有奇数个1,没有-1一定不行
从任一节点dfs,看别人的代码在dfs完所有子树后都有这样的操作 if(d[to] == 1) d[pos] ^= 1
想了好久,模拟了一下,也就是从靠近树叶的d为1的节点回溯,如果父节点为0改为1,为-1则直接找到停下来
另外还要用并查集去环
#includeusing namespace std;#define MAXN 300005struct edge { int dest, num; };int n, m, f[MAXN];int cnt, ans[MAXN];int root, d[MAXN];vector a[MAXN];void work(int pos, int fa) { for (unsigned i = 0; i < a[pos].size(); i++) { if (a[pos][i].dest == fa) continue; work(a[pos][i].dest, pos); if (d[a[pos][i].dest] == 1) { ans[++cnt] = a[pos][i].num; if (d[pos] != -1) d[pos] ^= 1; } }}int F(int x) { if (f[x] == x) return x; else return f[x] = F(f[x]);}int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &d[i]); f[i] = i; } for (int i = 1; i <= m; i++) { int x, y; scanf("%d%d", &x, &y); if (F(x) == F(y)) continue; f[F(x)] = F(y); a[x].push_back((edge) {y, i}); a[y].push_back((edge) {x, i}); } root = 1; for (int i = 1; i <= n; i++) if (d[i] == -1) { root = i; break; } work(root, 0); if (d[root] == 1) printf("-1\n"); else { printf("%d\n", cnt); for (int i = 1; i <= cnt; i++) printf("%d ", ans[i]); printf("\n"); } return 0;}