6827 Road To The 3rd Building

算每个sks_ksk​的贡献,s1s_1s1​要乘的分子和为(1+1/2+…+1/n),s2s_2s2​为(1+2/2+…+1/n),容易发现规律s2s_2s2​要乘以的分子和为s1s_1s1​要乘的分子和+(1/2+…+1/(n-1)),依次类推,每次分子和是上一个加上sum[st-1]-sum[ed-1-1](sum[i]表示1+1/2+…+1/i的逆元)。
此外容易发现sis_isi​与sn−i+1s_{n-i+1}sn−i+1​要乘的分子和是相同的。
因此可以O(n)来计算答案。

#include<cstdio>
using namespace std;
typedef long long ll;
const ll p = 1e9 + 7;
const int maxn = 2e5 + 5;
int T, n;
ll s[maxn], inv[maxn], sum[maxn];
int main(void) {//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);inv[0] = inv[1] = 1;for (int i = 2; i < maxn; i++) {inv[i] = (p - p / i) * inv[p % i] % p;}for (int i = 1; i < maxn; i++)sum[i] = (sum[i - 1] + inv[i]) % p;scanf("%d", &T);while (T--) {scanf("%d", &n);for (int i = 1; i <= n; i++)scanf("%lld", &s[i]);ll ans = 0, invSum = 0;int m = n / 2, st = 1, ed = n;for (int i = 1; i <= m; i++) {invSum = (invSum + ((sum[ed] - sum[st - 1]) % p + p) % p) % p;ans = (ans + (s[i] + s[n - i + 1]) % p * invSum % p) % p;st++; ed--;}if (n & 1) {m++; invSum = (invSum + ((sum[ed] - sum[st - 1]) % p + p) % p) % p;ans = (ans + s[m] * invSum % p) % p;}printf("%lld\n", ans * inv[n] % p * inv[n + 1] % p * 2 % p);}return 0;
}

6828 Little Rabbit’s Equation

Little Rabbit’s Equation
形式为:非负数 运算符 非负数 = 非负数
注意:最小为2进制,开long long

#include<cstdio>
#include<iostream>
#include<string>
#include<stack>
using namespace std;
typedef long long ll;
int num[256];
string line;
ll cal(string s, int digit) {int pos = s.length();char ch = '+';for (int i = 0; i < s.length(); i++) {if (isdigit(s[i]) || isalpha(s[i]))continue;ch = s[i];pos = i;break;}ll t1 = 0, t2 = 0;for (int i = 0; i < pos; i++) {if (isdigit(s[i]))t1 = t1 * digit + s[i] - '0';if (isalpha(s[i]))t1 = t1 * digit + num[s[i]];}for (int i = pos + 1; i < s.length(); i++) {if (isdigit(s[i]))t2 = t2 * digit + s[i] - '0';if (isalpha(s[i]))t2 = t2 * digit + num[s[i]];}ll res = t1;if (ch == '+')res = res + t2;if (ch == '-')res = res - t2;if (ch == '*')res = res * t2;if (ch == '/') {if (res % t2 == 0) res = res / t2;else res = -1;}return res;
}
int main(void) {num['A'] = 10; num['B'] = 11; num['C'] = 12;num['D'] = 13; num['E'] = 14; num['F'] = 15;while (cin >> line) {int minxx = 0;for (int i = 0; i < line.length(); i++) {if (isdigit(line[i])) {if (minxx<9 && line[i] - '0' > minxx)minxx = line[i] - '0';}else if (isalpha(line[i])) {if (num[line[i]] > minxx)minxx = num[line[i]];}}int ans = -1, pos = line.find('=');for (int digit = minxx + 1; digit <= 16; digit++) {if (ans != -1)break;ll a = cal(line.substr(0, pos), digit);ll b = cal(line.substr(pos + 1), digit);if (a == b)ans = digit;}if (ans == 1)ans++;printf("%d\n", ans);}return 0;
}

6829 Borrow

对于数x,y,z(x≥y≥z)x,y,z(x\geq y \geq z)x,y,z(x≥y≥z),若和不为3的倍数显然无解输出-1;取mmm作为平均数,可先从xxx中拿出x−mx-mx−m元钱分配给yyy和zzz,假设分配给zzz为ttt元,则有序列,z+t,m,y+x−m−tz+t,m,y+x-m-tz+t,m,y+x−m−t,可以看成是m−c,m,m+cm-c,m,m+cm−c,m,m+c的等差序列,然后又要从m+cm+cm+c中拿ccc元分配给另外两人,假设期望值为fcf_cfc​,则得到公式fc=c+12c∑i=0cCcifif_c=c+\frac{1}{2^c}\sum^c_{i=0}C_c^if_ifc​=c+2c1​∑i=0c​Cci​fi​
摘自:https://www.cnblogs.com/wasa855/p/13448251.html

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const ll maxn = 1e6 + 5;
ll t, a[3];
ll qpow(ll a, ll b) {ll res = 1;while (b){if (b & 1)res = (res * a) % mod;a = a * a % mod;b >>= 1;}return res;
}
ll Inv(ll x) { return qpow(x, mod - 2); }
ll inv[maxn], pow2[maxn], fac[maxn];
ll Cmn(ll m, ll n) {if (!n)return 1;return fac[m] * inv[n] % mod * inv[m - n] % mod;
}
int main(void) {inv[0] = inv[1] = pow2[0] = fac[0] = fac[1] = 1, pow2[1] = 2;for (ll i = 2; i < maxn; i++) {inv[i] = inv[i - 1] * Inv(i) % mod;pow2[i] = pow2[i - 1] * 2 % mod;fac[i] = fac[i - 1] * i % mod;}scanf("%lld", &t);while (t--){scanf("%lld %lld %lld", &a[0], &a[1], &a[2]);if ((a[0] + a[1] + a[2]) % 3) { printf("-1\n"); continue; }ll m = (a[0] + a[1] + a[2]) / 3;sort(a, a + 3);ll ans = 0;for (ll t = 0; t <= a[2] - m; t++) {ll now = min(a[0] + t, a[1] + a[2] - m - t);ll c = m - now;ans = (ans + Cmn(a[2] - m, t) * 2 % mod * c % mod) % mod;}printf("%lld\n", (ans * Inv(pow2[a[2] - m]) % mod + a[2] - m) % mod);}return 0;
}

6830 Asteroid in Love

遍历两个类型点组成线段,与第三类的点构成三角形,易知第三类的点一定是凸包上的点才有面积最大的效果。对凸包分为上下两部分,进行三分求极限。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
const int maxn = 3e3 + 5;
const double eps = 1e-8;
typedef long long ll;
int sgn(double x) {if (fabs(x) < eps)return 0;else return x < 0 ? -1 : 1;
}
struct Point {ll x, y;Point() {}Point(ll x, ll y) :x(x), y(y) {}Point operator + (Point B) { return Point(x + B.x, y + B.y); }Point operator - (Point B) { return Point(x - B.x, y - B.y); }bool operator < (Point B) {return sgn(x - B.x) < 0 || (sgn(x - B.x) == 0 && sgn(y - B.y) < 0);}
};
typedef Point Vector;
ll Cross(Vector A, Vector B) { return A.x * B.y - A.y * B.x; }
void Convex_hull(Point* p, int n, Point* ch, int& top, int op) {if (op) {for (int i = 0; i < n; i++) {while (top > 1 && sgn(Cross(ch[top - 1] - ch[top - 2], p[i] - ch[top - 2])) <= 0)top--;ch[top++] = p[i];}}else {for (int i = n - 1; i >= 0; i--) {while (top > 1 && sgn(Cross(ch[top - 1] - ch[top - 2], p[i] - ch[top - 2])) <= 0)top--;ch[top++] = p[i];}}
}int T, n, cnt[3];
Point p[3][maxn], ch1[maxn], ch2[maxn];ll getArea(Point a, Point b, int top1, int top2) {ll res = 0;int l = 0, r = top1;while (r - l >= 3) {int lmid = (l + l + r) / 3;int rmid = (l + r + r) / 3;if (abs(Cross(a - b, a - ch1[lmid])) > abs(Cross(a - b, a - ch1[rmid])))//比较面积大小r = rmid;elsel = lmid;}for (int i = l; i <= r; i++)res = max(res, abs(Cross(a - b, a - ch1[i])));l = 0, r = top2;while (r - l >= 3) {int lmid = (l + l + r) / 3;int rmid = (l + r + r) / 3;if (abs(Cross(a - b, a - ch2[lmid])) > abs(Cross(a - b, a - ch2[rmid])))r = rmid;elsel = lmid;}for (int i = l; i <= r; i++)res = max(res, abs(Cross(a - b, a - ch2[i])));return res;
}int main(void) {//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);scanf("%d", &T);while (T--) {scanf("%d", &n);cnt[0] = cnt[1] = cnt[2] = 0;for (int i = 0; i < n; i++) {double a, b; int c;scanf("%lf %lf %d", &a, &b, &c);p[c][cnt[c]++] = Point(a, b);}sort(p[2], p[2] + cnt[2]);int top1 = 0, top2 = 0;Convex_hull(p[2], cnt[2], ch1, top1, 1);Convex_hull(p[2], cnt[2], ch2, top2, 0);ll ans = 0;for (int i = 0; i < cnt[0]; i++) {for (int j = 0; j < cnt[1]; j++) {ans = max(ans, getArea(p[0][i], p[1][j], top1 - 1, top2 - 1));}}if (ans & 1)printf("%lld.5\n", ans / 2);else printf("%lld.0\n", ans / 2);}return 0;
}

6831 Fragrant numbers

区间DP题,预处理,1e8左右的操作数时间挺够的。

#include<cstdio>
using namespace std;
const int maxn = 5000 + 5;
const int maxl = 14;
bool dp[15][15][maxn];
int num[15] = { 0,1,1,4,5,1,4,1,9,1,9,1,1,4,5 };
int N;
int main(void) {for (int i = 1; i <= 14; i++) {int x = 0;for (int j = i; j <= maxl; j++) {x = x * 10 + num[j];if (x >= maxn)break;dp[i][j][x] = 1;}}for (int len = 2; len < maxl; len++)for (int L = 1; L + len - 1 <= maxl; L++) {int R = L + len - 1;for (int mid = L; mid < R; mid++)for (int val1 = 1; val1 < maxn; val1++)if (dp[L][mid][val1])for (int val2 = 1; val2 < maxn; val2++)if (dp[mid + 1][R][val2]) {if (val1 + val2 < maxn)dp[L][R][val1 + val2] = 1;if (val1 * val2 < maxn)dp[L][R][val1 * val2] = 1;}}//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);int t;scanf("%d", &t);while (t--) {scanf("%d", &N);int ans = -1;for (int i = 1; i <= 14; i++)if (dp[1][i][N]) { ans = i; break; }printf("%d\n", ans);}return 0;
}

6832 A Very Easy Graph Problem

显然新加入的边一定比已经生成的路径都要大,所以建立最小生成树就能实现所求的最小距离。一次性DFS求出每条边的一个方向上的所有黑点和白点,则相反方向的黑点白点可以由总数减去已求的部分。交叉相乘相加再乘边权就是该边对答案的贡献。

注意:在使用权值时最好临时获取对应的2^i次方,即开始只存边的编号,否则可能出现数据错误(原因未知)

#include<cstdio>
#include<vector>
#include<cstring>
#include<queue>
using namespace std;
typedef long long ll;
const ll p = 1e9 + 7;
const int maxn = 1e5 + 5;
const int maxm = 2e5 + 5;
int T, n, m, a[maxn], fa[maxn], vis[maxn];
ll white[maxm], black[maxm], w[maxm];
struct cosId {int to, id;cosId(int to, int id) :to(to), id(id) {}
};
vector<cosId>e[maxn];
struct edge {int from, to;ll weight;edge(int u, int v, ll w) :from(u), to(v), weight(w) {}bool operator<(const edge& rhs)const {return weight > rhs.weight;}
};
struct Res {int wtn, bkn;Res(int w = 0, int b = 0) :wtn(w), bkn(b) {}
};
void init() {for (int i = 1; i <= n; i++) {fa[i] = i;e[i].clear();}memset(white, 0, sizeof(white));memset(black, 0, sizeof(black));memset(vis, 0, sizeof(vis));
}
int find(int x) {return fa[x] == x ? x : fa[x] = find(fa[x]);
}
void merge(int x, int y) {x = find(x);y = find(y);if (x != y)fa[y] = x;
}
Res dfs(int u) {vis[u] = 1;Res res;for (int i = 0; i < e[u].size(); i++) {int v = e[u][i].to;if (vis[v])continue;Res tmp = dfs(v);white[e[u][i].id] = tmp.wtn;black[e[u][i].id] = tmp.bkn;res.wtn += tmp.wtn;res.bkn += tmp.bkn;}if (a[u])res.bkn++;else res.wtn++;return res;
}
int main(void) {//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);w[0] = 1;for (int i = 1; i < maxm; i++)w[i] = (w[i - 1] << 1) % p;scanf("%d", &T);while (T--) {scanf("%d %d", &n, &m); init();ll Bsum = 0, Wsum = 0;for (int i = 1; i <= n; i++) {scanf("%d", &a[i]);if (a[i])Bsum++;else Wsum++;}priority_queue<edge>pq;for (int i = 1; i <= m; i++) {int u, v;scanf("%d %d", &u, &v);pq.push(edge(u, v, i));}vector<int>ans;int cnt = 1;while (cnt != n) {int u, v;u = pq.top().from;v = pq.top().to;if (find(u) == find(v)) {pq.pop(); continue;}merge(u, v);e[u].push_back(cosId(v, cnt - 1));e[v].push_back(cosId(u, cnt - 1));ans.push_back(pq.top().weight);pq.pop();cnt++;}dfs(1);ll sum = 0;for (int i = 0; i < ans.size(); i++) {ll tmpB = Bsum - black[i];ll tmpW = Wsum - white[i];sum = ((sum + (tmpB * white[i] % p *w[ans[i]] % p) % p + (tmpW * black[i] % p * w[ans[i]] % p))) % p;}printf("%lld\n", sum);}return 0;
}

6835 Divisibility


题意是f(f(…f(y)…))被x整除等价于y被x整除,显然x>=b时不成立,式子最后的结果小b

若x<b,当f(f(…f(y)…))被x整除时有:
y=c1∗(bn−1−1)+c2∗(bn−2−1)+⋯+cn∗(b0−1)+(c1+c2+⋯+cn)y=c_1*(b^{n-1}-1)+c_2*(b^{n-2}-1)+\cdots+c_n*(b^{0}-1)+(c_1+c_2+\cdots+c_n)y=c1​∗(bn−1−1)+c2​∗(bn−2−1)+⋯+cn​∗(b0−1)+(c1​+c2​+⋯+cn​)
最后的部分被x整除,若y被x整除,则b-1为x的倍数即可,容易验证,b-1不为x的倍数时,y不被x整除。

#include<cstdio>
using namespace std;
typedef long long ll;
int t;
ll b, x;
int main(void) {scanf("%d", &t);while (t--){scanf("%lld%lld", &b, &x);printf("%c\n", (b - 1) % x == 0 ? 'T' : 'F');}return 0;
}

6836 Expectation


矩阵树定理用于无向图:
n个点的图,建立n*n矩阵,矩阵中第i行第i列的元素为结点i的度数,第i行第j列为结点i与结点j的边数的负值,任意去掉一行和一列后的行列式值即为改图的生成树个数。

如何证明未知,详细请去百度。

#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int, int>PII;
const ll mod = 998244353;
const int maxm = 1e4 + 5;
const int maxn = 105;
int t, n, m;
ll qpow(ll a, ll b) {ll res = 1;while (b) {if (b & 1)res = (res * a) % mod;a = a * a % mod;b >>= 1;}return res;
}
ll inv(ll x) { return qpow(x, mod - 2); }
struct edge {int u, v;ll w;
}e[maxm];
ll K[maxn][maxn];
ll Guass() {ll res = 1;for (int i = 1; i < n; i++) {//依次把第i列,从第i+1行到第n行变为0for (int j = i + 1; j < n; j++) {while (K[j][i]) {//直到为0ll t = K[i][i] / K[j][i];//计算第i列,第i行是第j行的几倍for (int k = i; k < n; k++) {K[i][k] = (K[i][k] - t * K[j][k] % mod + mod) % mod;swap(K[i][k], K[j][k]);//把第i行元素变为0后与第j行交换}res = -res;//每次交换行 值变为原来的负数}}if (!K[i][i])return 0;res = (res * K[i][i] % mod + mod) % mod;//将行列式化为上三角行列式后 值为对角线元素的乘积}return res;
}
int main(void) {//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);scanf("%d", &t);while (t--) {scanf("%d %d", &n, &m);memset(K, 0, sizeof(K));for (int i = 0; i < m; i++) {int u, v; ll w;scanf("%d %d %lld", &u, &v, &w);e[i].u = u; e[i].v = v; e[i].w = w;K[u][v]--;K[v][u]--;K[u][u]++;K[v][v]++;}ll sum = Guass(), ans = 0;for (int k = 0; k <= 30; k++) {memset(K, 0, sizeof(K));for (int i = 0; i < m; i++) {int u = e[i].u, v = e[i].v;ll ee = (e[i].w & (1LL << k)) ? 1 : 0;K[u][u] += ee;K[v][v] += ee;K[u][v] -= ee;K[v][u] -= ee;}ans = (ans + Guass() * (1LL << k) % mod) % mod;}printf("%lld\n", (ans * inv(sum) % mod + mod) % mod);}return 0;
}

2020 HDU Multi-University Training Contest 6(部分)相关推荐

  1. HDU 2019 Multi-University Training Contest 1 杭电2019多校联合训练赛 第一场 1001 Blank (6578)

    HDU 2019 Multi-University Training Contest 1 杭电2019暑期多校集训第一场 1001 Blank (6578) Problem Description T ...

  2. 2020 GDUT Winter Personal Training Contest I (Div. 2) B - Divisors of Two Integers题解

    原题 题目大意 给出一段数,这些数字是两个数的所有因数,找回这两个数 题目分析 简单分析一下可以发现最大的数一定是其中一个答案(花了10min意识到),然后就很简单了,去掉一个数的所有因子,剩下最大的 ...

  3. HDU 6091 - Rikka with Match | 2017 Multi-University Training Contest 5

    思路来自 某FXXL 不过复杂度咋算的.. /* HDU 6091 - Rikka with Match [ 树形DP ] | 2017 Multi-University Training Conte ...

  4. HDU 6051 - If the starlight never fade | 2017 Multi-University Training Contest 2

    /* HDU 6051 - If the starlight never fade [ 原根,欧拉函数 ] | 2017 Multi-University Training Contest 2 题意: ...

  5. HDU 6058 - Kanade's sum | 2017 Multi-University Training Contest 3

    /* HDU 6058 - Kanade's sum [ 思维,链表 ] | 2017 Multi-University Training Contest 3 题意:给出排列 a[N],求所有区间的第 ...

  6. hdu 4925 Apple Tree--2014 Multi-University Training Contest 6

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others ...

  7. HDU 6638 [2019 Multi-University Training Contest 6]

    Snowy Smile Problem Description There are n pirate chests buried in Byteland, labeled by 1,2,-,n. Th ...

  8. 【水一波题解】题解 of University of Central Florida 2020 (Fall) “Practice” Local Programming Contest

    题解 of University of Central Florida 2020 (Fall) "Practice" Local Programming Contest [by_0 ...

  9. 2017 Multi-University Training Contest - Team 3 Kanade's sum hd6058

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6058 题目: Kanade's sum Time Limit: 4000/2000 MS (J ...

  10. 2018 Multi-University Training Contest 3 Problem F. Grab The Tree 【YY+BFS】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6324 Problem F. Grab The Tree Time Limit: 2000/1000 MS ...

最新文章

  1. 庞锋 OpenCV 视频 学习进度备忘
  2. linux 卸载 openssl,请教Linux下Openssl安装的问题。
  3. c语言兔子繁殖问题分析和递归方程,经典的兔子生兔子问题(C#递归解法)
  4. 接雨水—leetcode42
  5. javescript的内置对象
  6. 【华为云技术分享】云图说 | Dubbo框架应用也可以使用Istio服务网格
  7. form空白及iframe空白处理
  8. delphi 联合体_校园动态 | 西安市碑林区大学南路小学“名校+”教育联合体召开“合木论坛”...
  9. 硅谷大佬们屡次推荐的10本书,你看过几本?
  10. [19保研]中国科学院沈阳计算技术研究所教育中心2019年保研夏令营通知
  11. android自动烧写工具,MiniTools(Android内核烧录软件) v1.1 官方安装免费版
  12. word之无法插入公式,公式图标灰色
  13. [转]库存那些事儿_8_盘点
  14. 怎样在计算机上设置纸大小,电脑中打印机设备自定义纸张打印大小的方法
  15. 计算机msvcp100.dll,msvcp100.dll丢失的解决方法
  16. android 在线获取音乐歌词lrc文件
  17. 开源问答系统开源软件
  18. UE4--局域网多人联机
  19. MOSFET正温度系数和负温度系数
  20. GBase XDM集群服务配置

热门文章

  1. JavaWeb网上商城项目中用户注册,使用MailServer和FoxMail搭建本地邮件服务器
  2. 树莓派4支持多大tf卡_树莓派入门指南(Raspberry Pi)
  3. 爬虫 - 股票爬虫实例之雪球网
  4. 文件夹排序(先文件夹排序,后文件排序)
  5. 袁国宝:罗永浩直播之道
  6. 等保2.0详解(附3级检查表)
  7. 家居物联网(IoT)接入控制与认证的再思考
  8. 空降了位前阿里的领导,三个月后我被离职了!
  9. 夜深人静刷力扣(2)
  10. 网上流传的飞扬学院Java_收获| 云和JAVA、UI双班毕业,飞扬青春再出发!