9-27 DAIRY
来源:互联网 发布:网络溜溜球的意思 编辑:程序博客网 时间:2024/06/14 15:16
今天分很低,但也不完全是该拿到得分没拿到,说实话我要是写了第一题估计也是错的,为什么大家都100分啊,好厉害= =
T1 a 30
solution里写了两个算法,实际上能过的其实有三种。
算法1:注意到 (a/b) mod c = [a mod (b*c) ]/b (出题人说这是模的一个性质。)
证:(以下证明又长又繁琐可能又不清楚可以略过)
建议自备纸笔跟着我的节奏【○ ○】
∵a = i*b + j
又∵i = h*c + k
那么就是说我们要求的就是k.
现在倒过来。
∵a = i*b+j
∴i = h*c+k
∴a = (h*c+k)*b+j = h*b*c+k*b+j
此时要求的是k.又已知a、b、c.
观察到这个式子:a = h*b*c+k*b+j . .. 将a%(b*c)可以得到k*b+j.
再/b,可以得到k即答案.(因为计算机计算“/”直接会把k去掉)
∴(a/b) mod c = [a mod (b*c) ]/b .
证毕。
以下为改完正确的代码。
#include<cstdio>#include<cstdlib>#include<iostream>#include<algorithm>#include<cstring>using namespace std;typedef long long ll;const int N = 1000000+5;char a[N];ll b, c;int main(){ freopen("a.in", "r", stdin); freopen("a.out", "w", stdout); scanf("%s %lld%lld", a, &b, &c); ll p = b*c; ll ret = 0LL; for(int i = 0; i < strlen(a); i++) ret = (ret*10%p + a[i]-'0')%p; printf("%lld\n", ret/b); return 0;}
算法2:注意到 (a/b) mod c = [a- (a mod b)] * b^(-1) mod c【那个b^(-1)是指算b的逆元】
这个解释就是说,一般我们做除法改成逆元是必须被除数是除数的整数倍,而这里不一定正好整除,所以我们需要自己调整为整除情况才可以用上逆元。所以用a-(a%b)可得到a/b向下取整的情况,再利用扩展欧几里得求逆元计算即可。【没写这份代码】
算法3:做高精度除法,比较麻烦吧???反正我懒得写……..
T2 b 10
题面比较坑,输入的时候要注意输入起始位置是先snuke再蜘蛛,而输入边时是先蜘蛛在snuke….被坑了。
通过手推观察可知:
以B为根对蜘蛛丝边进行一遍dfs得到蜘蛛丝上深度dep1[];
以A为根对树边进行一遍dfs得到树边上的深度dep2[];
一个点的dep1[i] <= dep2[i]的话,A【snuke】是不会去的,然后从这个点到其他点也不可能了,这种情况直接continue;最终答案即是所有可以到达的点中dep1[]的最大值。
改完的正确程序。
#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>#include<vector>using namespace std;typedef long long ll;const int N = 200000+5;const int oo = 2147483647;int ans, n, a, b;int dep1[N], dep2[N];struct node{ int head[N], to[N*2], next[N*2], e; void add(int x, int y){ to[++e] = y; next[e] = head[x]; head[x] = e; to[++e] = x; next[e] = head[y]; head[y] = e; }}A, B;template <typename T>T read(){ T N(0), F(1); char C = getchar(); for(; !isdigit(C); C = getchar()) if(C == '-') F = -1; for(; isdigit(C); C = getchar()) N = N*10 + C-48; return N*F;}void dfs1(int u, int lst = 0){ for(int i = A.head[u]; i; i = A.next[i]){ int v = A.to[i]; if(v == lst) continue; dep1[v] = dep1[u]+1; dfs1(v, u); }}void dfs2(int u, int lst = 0){ ans = max(ans, dep1[u]); for(int i = B.head[u]; i; i = B.next[i]){ int v = B.to[i]; if(v == lst) continue; dep2[v] = dep2[u]+1; if(dep1[v] <= dep2[u]) continue; dfs2(v, u); }}int main(){ freopen("b.in", "r", stdin); freopen("b.out","w",stdout); n = read<int>(); a = read<int>(); b = read<int>(); for(int i = 1; i < n; i++){ int x, y; x = read<int>(), y = read<int>(); A.add(x, y); } for(int i = 1; i < n; i++){ int x, y; x = read<int>(), y = read<int>(); B.add(x, y); } dfs1(b); dfs2(a); printf("%d\n", ans); return 0;}
T3 c 30
暴力写的30。正解也不想探究了,应该是没太多意义的= =【难】
就够了(吧)
- 9-27 DAIRY
- 8-27 DAIRY
- 8-9 DAIRY
- 9-2 DAIRY
- 9-3 DAIRY
- 9-7 DAIRY
- 9-10 DAIRY
- 9-11 DAIRY
- 9-16 DAIRY
- 9-24 DAIRY
- 9-26 DAIRY
- 9-28 DAIRY
- dairy
- Dairy
- dairy
- 11.2dairy
- 11.3dairy
- 11.4dairy
- html入门篇--css优先级
- docker 私服
- Linux环境编程主要头文件分析
- Win10使用附件中的远程桌面连接Ubuntu 16.04图形界面(xrdp方法)
- JAVA date类型处理的一些小知识
- 9-27 DAIRY
- 字符串(含汉字)与十六进制互转js脚本-utf
- 通过form的action属性提交表单并接收处理返回值的方法(页面不跳转)
- 嵌入式Linux开发,开源项目
- 大数据学习第2天----------------linux 安装mysql 出现安装依赖问题解决(centos7)
- Echars学习-动态隐藏扇形区域的文字描述。
- Tensorflow-常用函数
- 学习前端第二天--javascript入门
- 打开ftp服务器上的文件夹时发生错误,请检查是否有权限访问该文件夹