有的代码是现场写的可能比较难看,懒得改了……凑合看下吧。
找时间补补

A. Ball

分类讨论。

#include <bits/stdc++.h>#define LOG(FMT...) fprintf(stderr, FMT)using namespace std;typedef long long ll;struct Disjoint_Set_Union
{int father[200005];int size[200005];int edge[200005];int F[200005];void reset(int n){for(int i = 1; i <= n; i++)father[i] = i;fill(&size[1], &size[n]+1, 1);fill(&edge[1], &edge[n]+1, 0);fill(&F[1], &F[n]+1, 0);}int get_root(int i){if(father[i] == i)return i;elsereturn father[i] = get_root(father[i]);}
};int main()
{#ifndef ONLINE_JUDGEfreopen("test.in", "r", stdin);
#endifconst int P = 10000019;int t;scanf("%d", &t);static Disjoint_Set_Union dsu;static bool vis[200005];for(int _ = 1; _ <= t; _++) {int n, m;scanf("%d%d", &n, &m);dsu.reset(m);for(int _ = 1; _ <= n; _++) {int a, b;scanf("%d%d", &a, &b);if(a == b) {dsu.edge[dsu.get_root(a)]++;dsu.F[dsu.get_root(a)]++;}else if(dsu.get_root(a) == dsu.get_root(b)) {a = dsu.get_root(a);dsu.edge[a]++;}else {a = dsu.get_root(a);b = dsu.get_root(b);dsu.father[b] = a;dsu.size[a] += dsu.size[b];dsu.edge[a] += dsu.edge[b] + 1;dsu.F[a] += dsu.F[b];}}fill(&vis[0], &vis[m]+1, false);int ans = 1;for(int i = 1; i <= m; i++)if(! vis[dsu.get_root(i)]) {int j = dsu.get_root(i);vis[j] = true;if(dsu.edge[j] > dsu.size[j])ans = 0;else if(dsu.edge[j] == dsu.size[j] && ! dsu.F[j])ans = ans * 2 % P;else if(dsu.edge[j] == dsu.size[j] && dsu.F[j])ans = ans;elseans = (long long)ans * dsu.size[j] % P;}printf("%d\n", ans);}
}

B. Seal

C. Parade

类似均分纸牌,一个方向扫过去支付代价。

#include <bits/stdc++.h>#define LOG(FMT...) fprintf(stderr, FMT)using namespace std;typedef long long ll;const int N = 100010;int cnt[N][2];void solve() {memset(cnt, 0, sizeof(cnt));ll ans = 0;int n;scanf("%d", &n);for (int rep = 0; rep < n * 2; ++rep) {int x, y;scanf("%d%d", &x, &y);if (y < 1) {ans += 1 - y;y = 1;}if (y > 2) {ans += y - 2;y = 2;}if (x < 1) {ans += 1 - x;x = 1;}if (x > n) {ans += x - n;x = n;}++cnt[x][y - 1];}for (int i = 1; i <= n; ++i) {#define A cnt[i][0]
#define B cnt[i][1]--A;--B;if (A > 0 && B > 0) {ans += A + B;cnt[i + 1][0] += A;cnt[i + 1][1] += B;} else if (A <= 0 && B <= 0) {ans -= A + B;cnt[i + 1][0] += A;cnt[i + 1][1] += B;} else if (A <= 0 && B > 0) {if (-A > B) {ans += B;A += B;ans += abs(A);cnt[i + 1][0] += A;} else {ans += -A;B += A;ans += abs(B);cnt[i + 1][1] += B;}} else if (A > 0 && B <= 0) {if (A > -B) {ans += -B;A += B;ans += abs(A);cnt[i + 1][0] += A;} else {ans += A;B += A;ans += abs(B);cnt[i + 1][1] += B;}}}printf("%lld\n", ans);
}int main() {#ifndef ONLINE_JUDGEfreopen("test.in", "r", stdin);
#endifint t;scanf("%d",&t);while(t--)solve();
}

D. Circuit

FWT 板子。

#include <bits/stdc++.h>#define LOG(FMT...) fprintf(stderr, FMT)using namespace std;typedef long long ll;const int N = 15;int n, p, P;
int a[(1 << N) + 10], b[(1 << N) + 10];int norm(int x) { return x >= p ? x - p : x; }int Norm(int x) { return x >= P ? x - P : x; }void fwt(int* a) {for (int i = 0; i < n; ++i)for (int j = 0; j < 1 << n; ++j)if (!(j >> i & 1)) {int a0 = a[j], a1 = a[j | 1 << i];a[j] = Norm(a0 + a1);a[j | 1 << i] = Norm(a0 - a1 + P);}
}void deb(int* a) {for (int i = 0; i < 1 << n; ++i)LOG("%d ", a[i]);LOG("\n");
}void solve() {memset(a, 0, sizeof(a));memset(b, 0, sizeof(b));int x, y, z;scanf("%d%d%d%d%d", &n, &x, &y, &z, &p);P = p << n;while (x--) {int l, r, c;scanf("%d%d%d", &l, &r, &c);c = norm(c % p + p);a[l] = norm(a[l] + c);a[r + 1] = norm(a[r + 1] - c + p);}for (int i = 1; i < 1 << n; ++i) a[i] = norm(a[i] + a[i - 1]);while (y--) {int l, r, c;scanf("%d%d%d", &l, &r, &c);c = norm(c % p + p);b[l] = norm(b[l] + c);b[r + 1] = norm(b[r + 1] - c + p);}for (int i = 1; i < 1 << n; ++i) b[i] = norm(b[i] + b[i - 1]);fwt(a);fwt(b);for (int i = 0; i < 1 << n; ++i) a[i] = a[i] * (ll)b[i] % P;fwt(a);for (int i = 0; i < 1 << n; ++i) a[i] >>= n;for (int i = 1; i < 1 << n; ++i) a[i] = norm(a[i] + a[i - 1]);while (z--) {int l, r;scanf("%d%d", &l, &r);int ans = a[r];if (l)ans = norm(ans - a[l - 1] + p);printf("%d ", ans % p);}putchar('\n');
}int main()
{#ifndef ONLINE_JUDGEfreopen("test.in", "r", stdin);
#endifint t;scanf("%d", &t);while (t--)solve();
}

E. Coprime

容斥一下,vector 上二分。

#include <bits/stdc++.h>#define LOG(FMT...) fprintf(stderr, FMT)using namespace std;typedef long long ll;const int N = 100010;int n, m;
int a[N], mu[N];
vector<int> fac[N], ex[N];void pre(int n) {mu[1] = 1;for (int i = 1; i <= n; ++i) {for (int j = i + i; j <= n; j += i)mu[j] -= mu[i];}for (int i = 1; i <= n; ++i) {if (!mu[i]) continue;for (int j = i; j <= n; j += i)fac[j].push_back(i);}
}void solve() {fill(ex + 1, ex + 100001, vector<int>());scanf("%d%d", &n, &m);for (int i = 1; i <= n; ++i) {int x;scanf("%d", &x);for (int v : fac[x])ex[v].push_back(i);}int d = 0;while (m--) {int l, r, x;scanf("%d%d%d", &l, &r, &x);l ^= d; r ^= d; x ^= d;d = 0;for (int v : fac[x])d += mu[v] * (int)(upper_bound(ex[v].begin(), ex[v].end(), r) - lower_bound(ex[v].begin(), ex[v].end(), l));printf("%d\n", d);}
}int main()
{#ifndef ONLINE_JUDGEfreopen("test.in", "r", stdin);
#endifpre(100000);int t;scanf("%d", &t);while (t--) {solve();}
}

F. Graduation

暴力。

#include <bits/stdc++.h>#define LOG(FMT...) fprintf(stderr, FMT)using namespace std;typedef long long ll;struct Time
{int day;int l, r;
};int main()
{#ifndef ONLINE_JUDGEfreopen("test.in", "r", stdin);
#endifint t;scanf("%d", &t);for(int _ = 1; _ <= t; _++) {int already[6];for(int i = 1; i <= 5; i++)scanf("%d", &already[i]);int goal[6];for(int i = 1; i <= 5; i++) {scanf("%d", &goal[i]);goal[i] = max(goal[i] - already[i], 0);}int n;scanf("%d", &n);int id[11], type[11], d[11];vector<Time> time[11];for(int i = 1; i <= n; i++) {int k;scanf("%d%d%d%d", &id[i], &type[i], &d[i], &k);for(int _ = 1; _ <= k; _++) {int day, l, r;scanf("%d%d%d", &day, &l, &r);time[i].push_back({day, l, r});}}if(goal[1] + goal[2] + goal[3] + goal[4] + goal[5] > 25)printf("unable to graduate\n");else if(goal[1] == 0 && goal[2] == 0 && goal[3] == 0 && goal[4] == 0 && goal[5] == 0)printf("able to graduate\n");else {vector<int> ans(100);for(int sn = 2; sn < 1<<n+1; sn += 2) {int cnt[6] = {};for(int i = 1; i <= n; i++)if(sn & (1<<i))cnt[type[i]]++;if(cnt[3] > 1 || cnt[4] > 1 || cnt[5] > 1)continue;if(cnt[1] + cnt[2] + cnt[3] + cnt[4] + cnt[5] >= ans.size())continue;//----------------------------------//int score[6] = {};for(int i = 1; i <= n; i++)if(sn & (1<<i))score[type[i]] += d[i];if(score[1] + score[2] + score[3] + score[4] + score[5] > 25)continue;if(score[1] < goal[1] || score[2] < goal[2] || score[3] < goal[3] || score[4] < goal[4] || score[5] < goal[5])continue;//----------------------------------//bool vis[7][13] = {};for(int i = 1; i <= n; i++)if(sn & (1<<i))for(auto t : time[i])for(int i = t.l; i <= t.r; i++) {if(vis[t.day][i])goto TAG;elsevis[t.day][i] = true;}ans.clear();for(int i = 1; i <= n; i++)if(sn & (1<<i))ans.push_back(id[i]);TAG:;}if(ans.size() >= 98)printf("unable to graduate\n");else {sort(ans.begin(), ans.end());printf("able to graduate\n");for(auto i : ans)printf("%d ", i);printf("\n");}}}
}

G. Go and Oreo

H. Homomorphism

I. Chamber of Braziers

J. Matrix of Determinants

K. Winner Winner, Chicken Dinner!

PKU-CPC 2019 简要题解相关推荐

  1. Atcoder Yahoo Programming Contest 2019 简要题解

    A-C 直接放代码吧. A int n,k; int main() {n=read();k=read();puts(k<=(n+1)/2?"YES":"NO&quo ...

  2. 十二省联考 2019 简要题解

    xor 暴力. #include <bits/stdc++.h>using namespace std;typedef unsigned int uint;const int N = 52 ...

  3. 湖南省第十届蓝狐网络杯大学生计算机程序设计竞赛,2019年湖南省大学生计算机程序设计竞赛 (HNCPC2019) 简要题解...

    2019年湖南省大学生计算机程序设计竞赛 (HNCPC2019) 简要题解 update10.01 突然发现叉姐把这场的题传到牛客上了,现在大家可以有地方提交了呢. 不知道该干什么所以就来水一篇题解 ...

  4. Noip 2014酱油记+简要题解

    好吧,day2T1把d默认为1也是醉了,现在只能期待数据弱然后怒卡一等线吧QAQ Day0 第一次下午出发啊真是不错,才2小时左右就到了233,在车上把sao和fate补掉就到了= = 然后到宾馆之后 ...

  5. c语言1106回文数,Codeforces 1106 简要题解

    A题 传送门 读错题还能过样例我给自己点个赞. 题意简述:给一个010101网格SSS,问满足Si,j=Si+1,j+1=Si+1,j−1=Si−1,j−1=Si−1,j+1S_{i,j}=S_{i+ ...

  6. 【AtCoder】Japanese Student Championship 2019 Qualification题解

    Japanese Student Championship 2019 Qualification题解 A. Takahashi Calendar ◇题目传送门◆ 题目大意 定义Product Day为 ...

  7. 杂题记录及简要题解(一)

    一些前几天做过的还不错的但是不是太想专门花一整篇博客的篇幅去写的题就简要地记录在这里. 说是简要题解,其实写得还是挺详细的.之后的杂题记录可能就会写得简略一点. CF1060E Sergey and ...

  8. BJOI2018简要题解

    BJOI2018简要题解 D1T1 二进制 题意 pupil 发现对于一个十进制数,无论怎么将其的数字重新排列,均不影响其是不是 \(3\) 的倍数.他想研究对于二进制,是否也有类似的性质. 于是他生 ...

  9. [2019 年百度之星·程序设计大赛 - 初赛三]简要题解?

    UPD:AC代码放上去了 前言 老年贤者选手终于记得打百度之星了 Orz mayaohua2003 题目链接 最短路 1 n⊕1n \oplus 1n⊕1 Code #include <cstd ...

  10. 【NOI2019十二省联合省选】部分题简要题解

    Day 1 T1 异或粽子 题意:给出一个长为n的序列,选择K个不完全重合的区间使得每个区间的异或值的总和最大. 题解:先做一个前缀异或和,对于每一个右端点我们记录三元组(l,r,x)表示在左端点在\ ...

最新文章

  1. 高并发编程-使用wait和notifyAll进行线程间的通信3_多线程下的生产者消费者模型和notifyAll
  2. Hadoop入门(Hadoop2.7.2源码编译与伪分布安装)
  3. (30)FPGA面试题全局时钟资源及原语
  4. HTML项目代码编写规范
  5. Java爬取网页源代码解析
  6. 给你自己的博客加个 Markdown
  7. goaccess分析nginx日志
  8. STM32F7通过QSPI驱动W25Q256芯片
  9. 如何在电信光猫中查到自己的宽带密码
  10. 汤小丹计算机操作系统慕课版课后题答案第三章:处理机调度与死锁
  11. 怎样写好一篇英文论文
  12. php怎么画五星红旗,php基于GD库画五星红旗的方法,phpgd库五星红旗
  13. QQ号被盗了申诉回来马上又被盗了怎么办
  14. 判断平面内三点是否共线
  15. 【沧海拾昧】微机原理:存储器系统
  16. JavaCC中扩展的正规表达式
  17. python软件和rost软件哪个更好_ROST-CM软件分词和词频统计用法体验
  18. 计算机网络---应用层
  19. volatile限定符
  20. SVPWM的一些参数

热门文章

  1. 2022年机修钳工(初级)考试题库及在线模拟考试
  2. 关于IE浏览器开发人员工具无法打开的原因
  3. IT可以删除电脑里这些无用的文件
  4. 解决no st-link detected问题
  5. 国防科技大学计算机考研试题,国防科技大学历年操作系统考研试题
  6. 程序员思维-带你解读嫦娥奔月
  7. MTK 6735平台 低电量强开闪光灯
  8. Processing 案例 | 日本先生Atsushi Tanaka的3D世界
  9. 心灵乌鸡汤---motto
  10. 双竞集成国产芯片替代选型信息