2016 icpc沈阳部分题解
hdu5948 hdu5949 hdu5950 hdu5952 hdu5954
A Thickest Burger
对于每对 A B, 输出 max(2A+B,2B+A)max(2A + B, 2B + A)max(2A+B,2B+A)
B Relative atomic mass
给出一个字符串,只包含CHO,原子质量分别是12,1,16,求出这个字符串总的质量即可
C Recursive sequence
矩阵快速幂,式子是 a[i]=2a[i−2]+a[i−1]+i4a[i] = 2a[i - 2] + a[i - 1] + i^4a[i]=2a[i−2]+a[i−1]+i4,关键在于根据这个式子推导出转移矩阵,然后直接 lognlognlogn 实现即可
#include<bits/stdc++.h>
using namespace std;#define int long long
const int mod = 2147493647;struct matrix{int a[8][8];matrix(){memset(a, 0, sizeof a);}
};matrix mul(const matrix& x, const matrix& y){matrix ans;for(int i = 0; i < 7; ++i){for(int j = 0; j < 7; ++j){for(int k = 0; k < 7; ++k){ans.a[i][j] += x.a[i][k] * y.a[k][j];ans.a[i][j] %= mod;}}}return ans;
}matrix qpow(matrix a, int b){matrix ans;memcpy(ans.a, a.a, sizeof a.a);if(b == 0) return ans;b--;while(b){if(b & 1LL) ans = mul(ans, a);a = mul(a, a);b >>= 1LL;} return ans;
}signed main(){matrix A, B;A.a[0][2] = 16;A.a[0][3] = 8;A.a[0][4] = 4;A.a[0][5] = 2; A.a[0][6] = 1;B.a[0][0] = B.a[0][1] = 1;B.a[1][0] = 2;B.a[2][0] = B.a[2][2] = 1;B.a[3][0] = B.a[3][2] = 4;B.a[3][3] = 1;B.a[4][0] = B.a[4][2] = 6;B.a[4][3] = 3;B.a[4][4] = 1;B.a[5][0] = B.a[5][2] = 4;B.a[5][3] = 3;B.a[5][4] = 2;B.a[5][5] = 1;for(int i = 0; i < 7; ++i)B.a[6][i] = 1;B.a[6][1] = 0;int t;cin >> t;while(t--){int n, a, b;cin >> n >> a >> b;matrix C = A, D = B;C.a[0][1] = a;C.a[0][0] = b;if(n == 1){cout << a << endl;continue;}else if(n == 2){cout << b << endl;continue;}n -= 2;D = qpow(D, n);C = mul(C, D);cout << C.a[0][0] << endl;}return 0;
}
D Couting Cliques
给出一个无向图,有n个顶点和m条边,求顶点刚好为S的完全子图。
这里因为n只有100,m只有1000,S不超过10,所以直接爆搜,然后剪枝即可(一开始的时候还在苦苦想着有没有更好的想法,大意了)
#include<bits/stdc++.h>
using namespace std;const int N = 111;const int M = 1111;
int e[M], ne[M], h[N], idx;void add(int a, int b){e[idx] = b;ne[idx] = h[a];h[a] = idx++;
}int vis[N];
int mp[N][N];
int n, m, s;
int ans;
int a[11];
int at;inline int read() {int X = 0; bool flag = 1; char ch = getchar();while (ch < '0' || ch>'9') { if (ch == '-') flag = 0; ch = getchar(); }while (ch >= '0' && ch <= '9') { X = (X << 1) + (X << 3) + ch - '0'; ch = getchar(); }if (flag) return X;return ~(X - 1);
}void dfs(int now){if(at == s){ans++;return;}for(int i = h[now]; i != -1; i = ne[i]){int y = e[i];int flag = 1;if(y < now) continue;for(int j = 0; j < at; ++j){int z = a[j];if(mp[y][z] == 0){flag = 0;break;}}if(flag){a[at++] = y;dfs(y);at--;}}
}signed main(){int t;t = read();while(t--){memset(mp, 0, sizeof mp);memset(h, -1, sizeof h);idx = 0;ans = 0;at = 0;n = read(), m = read(), s = read();for(int i = 0; i < m; ++i){int u, v;u = read(), v = read();add(u, v);mp[u][v] = mp[v][u] = 1;}for(int i = 1; i <= n - s + 1; ++i){a[at++] = i;dfs(i);at--;}printf("%d\n", ans);}return 0;
}
E Do not pour out
当d >= 1 时,上面是一个完整的椭圆,用简单的推算直接求出椭圆的 aaa 和 bbb,椭圆面积公式 πab\pi abπab 即可。
关键是当 d < 1时,椭圆面是会被截去一部分的,如图
设 mid,t,ymid, t, ymid,t,y,根据相似三角形得到 tmid=2−y2\frac{t}{mid} = \frac{2 - y}{2}midt=22−y,所以有 t=(2−y)mid2t = \frac{(2 - y)mid}{2}t=2(2−y)mid
有效底面积是 θ+(t−1)sin(θ)\theta + (t - 1)sin(\theta)θ+(t−1)sin(θ),其中 θ=arccos(1−t)\theta = arccos(1 - t)θ=arccos(1−t),这里不需要特判 ttt 和 1 的大小关系,神奇的三角函数已经帮我们考虑这种关系了。
所以总结一下公式
①t=(2−y)mid2②θ=arccos(1−t)③S(t)=θ+(t−1)sin(θ)④V=∫02S(t(y))dy① \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ t = \frac{(2 - y)mid}{2}\\② \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \theta = arccos(1 - t)\\③ \ \ \ \ S(t) = \theta + (t - 1)sin(\theta)\\④ \ \ \ \ \ \ \ \ \ \ \ \ \ \ V = \int_{0}^{2}S(t(y))dy ① t=2(2−y)mid② θ=arccos(1−t)③ S(t)=θ+(t−1)sin(θ)④ V=∫02S(t(y))dy
然后就是代换,③代入④得到
⑤V=∫02(θ+(t−1)sinθ)dy⑤\ \ \ \ \ \ \ V = \int_{0}^{2}(\theta + (t - 1)sin\theta)dy ⑤ V=∫02(θ+(t−1)sinθ)dy
由①得 y=2−2tmidy = 2 - \frac{2t}{mid}y=2−mid2t,所以得到
⑥dy=−2midsinθdθ⑥\ \ \ \ \ \ dy = -\frac{2}{mid}sin\theta \ d\theta ⑥ dy=−mid2sinθ dθ
由②
⑦t=1−cosθ⑦\ \ \ \ \ t = 1 - cos\theta ⑦ t=1−cosθ
⑦代入⑤得到
⑧V=∫02(θ−sinθconθ)dy⑧\ \ \ \ \ \ \ \ V =\int_{0}^{2}(\theta - sin\theta con\theta)dy ⑧ V=∫02(θ−sinθconθ)dy
⑥代入⑧ 得到
⑨V=−2mid∫ab((θ−sinθcosθ)sinθ)dθ⑨\ \ \ \ \ \ \ \ \ V = -\frac{2}{mid}\int_{a}^{b}((\theta - sin\theta cos\theta)sin\theta)d\theta ⑨ V=−mid2∫ab((θ−sinθcosθ)sinθ)dθ
得到的⑨式中的积分区间是发生了变化的,从原来的对 yyy 积分变成了对 θ\thetaθ 积分,这里根据 公式⑥进行新区间范围计算 [arccos(1−mid),arccos(1)][arccos(1 - mid), arccos(1)][arccos(1−mid),arccos(1)],所以最后的积分公式为
⑩V=−2mid∫arccos(1−mid)arccos(1)(θsinθ−sin2θcosθ)dθ⑩\ \ \ \ \ \ \ \ \ V = -\frac{2}{mid}\int_{arccos(1 - mid)}^{arccos(1)}(\theta sin\theta - sin^2\theta cos\theta)d\theta ⑩ V=−mid2∫arccos(1−mid)arccos(1)(θsinθ−sin2θcosθ)dθ
然后就是求积分了,的到最后需要实现的计算公式
V=−2mid[sin(x)−xcos(x)−13sin3(x)]acos(a−mid)acos(1)V = -\frac{2}{mid}[sin(x) - x cos(x) - \frac{1}{3}sin^3(x)]_{acos(a - mid)}^{acos(1)} V=−mid2[sin(x)−xcos(x)−31sin3(x)]acos(a−mid)acos(1)
这样就可以通过二分求 midmidmid,得到 midmidmid 之后,可以求出斜面和底面的夹角 α\alphaα,根据图形得到以下关系
cosα=mid22+mid2=S底S0cos \alpha = \frac{mid}{\sqrt{2^2 + mid^2}} = \frac{S_底}{S_0} cosα=22+mid2mid=S0S底
这里 S0S_0S0 表示斜面面积, S底S_底S底 表示 S0S_0S0 在底面的投影,S底S_底S底 可以用②③公式求出来,所以答案就是
S0=S底22+mid2midS_0 = \frac{S_底 \sqrt{2^2 + mid^2}}{mid} S0=midS底22+mid2
#include<bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-10;double f(double x){return sin(x) - x * cos(x) - pow(sin(x), 3) / 3;
}double getV(double mid){double a = acos(1 - mid);double b = acos(1);return -2.0 / mid * (f(b) - f(a));
}double getS(double t){double theta = acos(1 - t);return theta + (t - 1) * sin(theta);
}int main(){int t;cin >> t;while(t--){double d;cin >> d;if(fabs(d) < eps){printf("%.5f\n", 0);continue;}if(d < 1){double l = 0, r = 2;while(fabs(r - l) > eps){double mid = (l + r) / 2;if(getV(mid) < PI * d)l = mid;else r = mid;}double mid = (l + r) / 2;double S = getS(mid);double S1 = S * sqrt(4 + mid * mid) / mid;printf("%.5f\n", S1);}else{double a = sqrt(1 + (2 - d) * (2 - d));double b = 1;double S = PI * a * b;printf("%.5f\n", S);}}return 0;
}
2016 icpc沈阳部分题解相关推荐
- 21年icpc沈阳站记录
icpc沈阳站记录 2021.11.22凌晨 从昨晚紧张到辗转反侧,虽然早就做好了打铁的心理准备,但待到比赛最后一刻两道铜牌题还没出时,满脑子的不甘心.当然最后肯定铁了395/576. 11.21也就 ...
- 2016 ICPC总结
2016 ICPC总结 九月份开学,开始知识点的补充,刚开始的几周都在刷acmsteps,十月开始进行专题性的学习,首先进行的数据结构,给自己定的计划,十一月前看完数据结构,刚开始的时候看的都是以前的 ...
- 训练实录 | 第 45 届ICPC沈阳站(牛客重现赛)
第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(沈阳)(重现赛) 传送门:ICPC沈阳 F - The Witchwood 这重现赛,这数据,我既然被hack了,我写的代码太拉跨了????? ...
- 2016 ICPC 北京网络赛 A 恶心模拟 F 循环矩阵,FFT(待补) I 模拟
2016 ICPC 北京网络赛 A - The Book List 题意:每本书有所属种类,给出原生的存放方式,求按新的方式存放的样子. tags:坑到心态爆炸的题== 直接堆进vector里搞的, ...
- 2018 ICPC 沈阳站
细胞色素训练3 排名:100/193 2018年ICPC沈阳站,学长在这里拿金了.听学长说开始时候很快的出了两题,排名第四,是可以进final的,然后一直没过题,直到最后封榜时候连过两题,金牌最后一名 ...
- 2021 ICPC 沈阳赛区J题 Luggage Lock
2021 ICPC 沈阳赛区J题 Luggage Lock 题意 有TTT组样例,其中每组样例为: 给定一个密码为b0b1b2b3b_0b_1b_2b_3b0b1b2b3的密码锁,已知当前密码 ...
- 第46届icpc 沈阳 J-Luggage Lock(思维 + 爆搜 / 队友玄学出法, 还没看懂)
第46届icpc 沈阳 J-Luggage Lock(思维 + 爆搜 / 队友玄学出法, 还没看懂) 题目来源:第46届icpc 沈阳 J-Luggage Lock 题意: 给出两个四位数的密码锁a和 ...
- 2019 ICPC 沈阳
2019 ICPC 沈阳 F(签到) 图中找度数为1的点 #include<iostream> #include<cstdio> #include<cstring> ...
- 2021 ICPC 沈阳站 D题 Journey to Un‘Goro (打表+找规律)
2021 ICPC 沈阳站 D.Journey to Un'Goro [链接][http://codeforces.com/gym/103202/problem/D](http://codeforce ...
最新文章
- leetcode--盛最多水的容器--python
- 张江男的逆袭,我如何使用leangoo提升团队效率
- ubuntu创建新用户并设置sudo权限
- 记录最近待学习的内容
- linux中的shell脚本case,Shell编程之case语句与循环语句
- php 5.4中php-fpm 的重启、终止操作命令
- 算法导论 9.1-1 “给出算法,在给定的比较次数(n+向上取整(lgn)-2)内,一定能找出第二小的元素。提示:也找出最小元素。”...
- 热腾腾的鸡汤,趁热。
- 使用github下载项目压缩包,打开前端项目加载依赖报错。
- 计算机软件实习每日学习打卡(1)20201130
- 淘宝-假货天堂 京东-吹牛大王 苏宁易购-中规中矩
- 只会用ping测试网络通不通?高级网工还会这么用
- html 播放本地视频(获取磁盘文件url)
- Linux驱动学习9(同步/异步与阻塞/非阻塞的区别 )
- flashcache安装使用
- @keyframes详解与实例
- 浮士德---法国:古诺
- java毕业设计springboot框架 java餐厅预约管理系统毕业设计开题报告功能参考
- 浏览器HTTP_USER_AGENT汇总——Firefox、Chrome、IE9、IE8、IE7、IE6
- css图片精灵定位_DIV CSS Sprites精灵 CSS图像拼合 CSS背景贴图定位教程案例
热门文章
- VB中上传下载文件到SQL数据库
- 5G与WiFi6空口技术对比
- 高通字库芯片GT20L16S1Y驱动 0.96寸 OLED 任意显示中文
- 公司旅游--金华武义二日游
- iPhone手机史上最全的扫盲帖【越狱,解锁,激活,Cydia,基带,裸机】
- 评估方法(交叉验证法、自助法、留出法)
- sml基本语法(三)——函数
- To B业务与To C业务(产品),用户需求,产品文档,技术和业务
- 26.JavaScript对象和基础类型之间的转换、hint、Symbol.toPrimitive、toString、valueOf
- 斗破苍穹java游戏美杜莎在哪_《斗破苍穹》四大魔兽体质排名,美杜莎的九彩吞天蟒仅排第二...