A.九九归一

题目:http://ch.ezoj.tk/contest/CH%20Round%20%2355%20-%20Streaming%20%236%20(NOIP模拟赛day2)/九九归一

题解:题目意思就是问 a是不是n的一个原根

首先如果 gcd(a,n)!=1 显然不可能 输出0

然后我们有性质

若 gcd(a,n)==1 则 a模n的阶k|phi(n)

所以就可以枚举phi(n)的约数判定了

复杂度题解中说是 q*logn*logn*logn的。。。

代码:

  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<cmath>
  4. #include<cstring>
  5. #include<algorithm>
  6. #include<iostream>
  7. #include<vector>
  8. #include<map>
  9. #include<set>
  10. #include<queue>
  11. #include<string>
  12. #define inf 1000000000
  13. #define maxn 100000
  14. #define maxm 500+100
  15. #define eps 1e-10
  16. #define ll long long
  17. #define pa pair<int,int>
  18. #define for0(i,n) for(int i=0;i<=(n);i++)
  19. #define for1(i,n) for(int i=1;i<=(n);i++)
  20. #define for2(i,x,y) for(int i=(x);i<=(y);i++)
  21. #define for3(i,x,y) for(int i=(x);i>=(y);i--)
  22. using namespace std;
  23. inline int read()
  24. {
  25. int x=,f=;char ch=getchar();
  26. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  27. while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
  28. return x*f;
  29. }
  30. int n,tot,a[maxn];
  31. int power(int xx,int yy)
  32. {
  33. ll t=,x=xx,y=yy;
  34. for(;y;y>>=,x=(x*x)%n)
  35. if(y&)t=(t*x)%n;
  36. return t;
  37. }
  38. inline bool check(int m)
  39. {
  40. for1(i,tot)if(power(m,a[i])==)return ;
  41. return ;
  42. }
  43. inline int gcd(int x,int y){return y?gcd(y,x%y):x;}
  44. int main()
  45. {
  46. freopen("input.txt","r",stdin);
  47. freopen("output.txt","w",stdout);
  48. n=read();
  49. int x=n,y=n;
  50. for2(i,,sqrt(n))
  51. if(x%i==)
  52. {
  53. y=(y/i)*(i-);
  54. while(x%i==)x/=i;
  55. }
  56. if(x!=)y=(y/x)*(x-);
  57. for1(i,y)if(y%i==)a[++tot]=i;tot--;
  58. int cs=read();
  59. while(cs--)
  60. {
  61. int m=read();
  62. if(gcd(m,n)!=)printf("");
  63. else if(check(m))printf("");
  64. else printf("");
  65. }
  66. printf("\n");
  67. return ;
  68. }

B.LCA的统计

题目:http://ch.ezoj.tk/contest/CH%20Round%20%2355%20-%20Streaming%20%236%20(NOIP模拟赛day2)/LCA的统计

题解:首先枚举是一定要的,我们枚举 lca(i,j)然后看一下什么样的i,j是我们枚举的这个值。

稍微想想会发现f[x]=w[x]*((s[x]*s[x])-sigma(s[y]*s[y])) y是x 的子树

然后防止爆long long 就行了

代码:

  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<cmath>
  4. #include<cstring>
  5. #include<algorithm>
  6. #include<iostream>
  7. #include<vector>
  8. #include<map>
  9. #include<set>
  10. #include<queue>
  11. #include<string>
  12. #define inf 1000000000
  13. #define maxn 1500000
  14. #define maxm 500+100
  15. #define eps 1e-10
  16. #define ll long long
  17. #define pa pair<int,int>
  18. #define for0(i,n) for(int i=0;i<=(n);i++)
  19. #define for1(i,n) for(int i=1;i<=(n);i++)
  20. #define for2(i,x,y) for(int i=(x);i<=(y);i++)
  21. #define for3(i,x,y) for(int i=(x);i>=(y);i--)
  22. #define mod 1000000007
  23. using namespace std;
  24. inline int read()
  25. {
  26. int x=,f=;char ch=getchar();
  27. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  28. while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
  29. return x*f;
  30. }
  31. struct edga{int go,next;}e[maxn];
  32. int n,tot,head[maxn];
  33. ll s[maxn],f[maxn],w[maxn];
  34. inline void insert(int x,int y)
  35. {
  36. e[++tot].go=y;e[tot].next=head[x];head[x]=tot;
  37. }
  38. void dfs(int x)
  39. {
  40. f[x]=;s[x]=w[x];
  41. for(int i=head[x],y;i;i=e[i].next)
  42. {
  43. dfs(y=e[i].go);
  44. f[x]=((f[x]-w[x]*(s[y]*s[y]%mod))%mod+mod)%mod;
  45. s[x]=(s[x]+s[y])%mod;
  46. }
  47. f[x]=(f[x]+w[x]*(s[x]*s[x]%mod))%mod;
  48. }
  49. int main()
  50. {
  51. freopen("input.txt","r",stdin);
  52. freopen("output.txt","w",stdout);
  53. n=read();w[]=read()%mod;
  54. for2(i,,n)insert(read(),i),w[i]=read()%mod;
  55. dfs();
  56. ll ans=;
  57. for1(i,n)ans=(ans+f[i])%mod;
  58. printf("%lld\n",ans);
  59. return ;
  60. }

C.四驱兄弟

题目:http://ch.ezoj.tk/contest/CH%20Round%20%2355%20-%20Streaming%20%236%20(NOIP模拟赛day2)/四驱兄弟

题解:猜想大概是MST,然后发现不会证,就打了弃疗了。结果A了。。。

出题人是这样说的:

考虑图连通的情况,那么假设最小生成树不是第k小边最小生成树,就可以把两个树各取一点变成一个更小的生成树,就矛盾了

没想到我用map+cin居然没T

代码:

  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<cmath>
  4. #include<cstring>
  5. #include<algorithm>
  6. #include<iostream>
  7. #include<vector>
  8. #include<map>
  9. #include<set>
  10. #include<queue>
  11. #include<string>
  12. #define inf 1100000000
  13. #define maxn 200000+1000
  14. #define maxm 500+100
  15. #define eps 1e-10
  16. #define ll long long
  17. #define pa pair<int,int>
  18. #define for0(i,n) for(int i=0;i<=(n);i++)
  19. #define for1(i,n) for(int i=1;i<=(n);i++)
  20. #define for2(i,x,y) for(int i=(x);i<=(y);i++)
  21. #define for3(i,x,y) for(int i=(x);i>=(y);i--)
  22. #define mod 1000000007
  23. using namespace std;
  24. typedef map<string,int>::const_iterator cit;
  25. typedef map<string,int>::value_type vt;
  26. inline int read()
  27. {
  28. int x=,f=;char ch=getchar();
  29. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  30. while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
  31. return x*f;
  32. }
  33. map<string,int>mp;
  34. struct rec{int u,v,w;}e[maxn];
  35. int n,m,tot,a[maxn],fa[maxn];
  36. string s;
  37. inline bool cmp(rec a,rec b)
  38. {
  39. return a.w<b.w;
  40. }
  41. inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
  42. int main()
  43. {
  44. freopen("input.txt","r",stdin);
  45. freopen("output.txt","w",stdout);
  46. n=read();m=read();
  47. for1(i,m)
  48. {
  49. e[i].w=read();
  50. cin>>s;
  51. cit j=mp.find(s);
  52. if(j!=mp.end())e[i].u=j->second;
  53. else
  54. {
  55. mp.insert(mp.begin(),vt(s,++tot));
  56. e[i].u=tot;
  57. }
  58. cin>>s;
  59. j=mp.find(s);
  60. if(j!=mp.end())e[i].v=j->second;
  61. else
  62. {
  63. mp.insert(mp.begin(),vt(s,++tot));
  64. e[i].v=tot;
  65. }
  66. }
  67. sort(e+,e+m+,cmp);
  68. for1(i,tot)fa[i]=i;
  69. int j=;
  70. for1(i,n)
  71. {
  72. while(j<=m&&find(e[j].u)==find(e[j].v))j++;
  73. if(j>m)a[i]=inf;
  74. else
  75. {
  76. a[i]=e[j].w;
  77. fa[find(e[j].u)]=find(e[j].v);
  78. }
  79. j++;
  80. }
  81. for1(i,n)
  82. if(a[i]==inf)printf("INF\n");else printf("%d\n",a[i]);
  83. return ;
  84. }

AK了好高兴,不过还是运气比较好的原因。jiry半小时AK实在不能再orz

CH Round #55 - Streaming #6 (NOIP模拟赛day2)的更多相关文章

  1. CH Round #55 - Streaming #6 (NOIP模拟赛day2)解题报告

    T1九九归一 描述 萌蛋在练习模n意义下的乘法时发现,总有一些数,在自乘若干次以后,会变成1.例如n=7,那么5×5 mod 7=4,4×5 mod 7=6,6×5 mod 7=2,2×5 mod 7 ...

  2. CH Round #55 - Streaming #6 (NOIP模拟赛day2)(被虐哭)

    http://ch.ezoj.tk/contest/CH%20Round%20%2355%20-%20Streaming%20%236%20%28NOIP%E6%A8%A1%E6%8B%9F%E8%B ...

  3. CH Round #49 - Streaming #4 (NOIP模拟赛Day2)

    A.二叉树的的根 题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模 ...

  4. CH Round #58 - OrzCC杯noip模拟赛day2

    A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...

  5. CH Round #48 - Streaming #3 (NOIP模拟赛Day1)

    A.数三角形 题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛D ...

  6. CH Round #54 - Streaming #5 (NOIP模拟赛Day1)

    A.珠 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2354%20-%20Streaming%20%235%20(NOIP模拟赛Day1)/珠 题解:sb题, ...

  7. CH Round #54 - Streaming #5 (NOIP模拟赛Day1)解题报告

    最近参加了很多CH上的比赛呢~Rating--了..题目各种跪烂.各种膜拜大神OTZZZ T1珠 描述 萌蛋有n颗珠子,每一颗珠子都写有一个数字.萌蛋把它们用线串成了环.我们称一个数字串是有趣的,当且 ...

  8. CH Round #54 - Streaming #5 (NOIP模拟赛Day1)(被虐瞎)

    http://ch.ezoj.tk/contest/CH%20Round%20%2354%20-%20Streaming%20%235%20%28NOIP%E6%A8%A1%E6%8B%9F%E8%B ...

  9. 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...

随机推荐

  1. 一不小心写了个bootstrap风格下拉控件 JqueryUI + bootstrap

    受够了EasyUI的封闭,Bootstrap虽然华丽但是功能太渣,闲着无聊写个下拉控件玩玩吧,不喜勿喷哈... 第一步:先设计下我的下拉控件的样子 1.既然是bootstrap风格的,我想应该是这样的 ...

  2. AIX Study之--AIX网卡配置管理(ent0、en0、et0)

    AIX Study之--AIX网卡配置管理(ent0.en0.et0) 1.查看AIX系统网卡信息: [root@aix211 /]#lsdev |grep et  en0 Available 1L- ...

  3. Amoeba是一个类似MySQL Proxy的分布式数据库中间代理层软件,是由陈思儒开发的一个开源的java项目

    http://www.cnblogs.com/xiaocen/p/3736095.html amoeba实现mysql读写分离 application  shang  2年前 (2013-03-28) ...

  4. Android入门之ActionBar实现Tab导航

    效果图: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android=&qu ...

  5. 打勾显示输入的密码 --EditText与setTransformationMethod

    实现目标: 实现原理: 为CheckBox添加一个监听器事件; 实现的源码: package edu.cquptzx.showPassword; import android.app.Activity ...

  6. 解决ajax请求cors跨域问题

    ”已阻止跨源请求:同源策略禁止读取位于 ***** 的远程资源.(原因:CORS 头缺少 'Access-Control-Allow-Origin').“ ”已阻止跨源请求:同源策略禁止读取位于 ** ...

  7. IIS7.5 提示未在本地计算机上注册“Microsoft.Jet.OleDb.4.0”提供程序

    在WIN7 X64平台IIS7.5,使用Asp.net连接access数据库时候,提示:未在本地计算机上注册“Microsoft.Jet.OleDb.4.0”提供程序. 说明: 执行当前 Web 请求 ...

  8. (转)关于c#中的事件

    原文链接http://blog.csdn.net/joyhen/article/details/8500211 如有不明白的地方欢迎加QQ群14670545 探讨 最近在看委托,然后看到事件,以前一直 ...

  9. 连接、关联、JOIN、APPLY(SQL Server)

    连接方式 连接类型 个人总结 阐述(生成两个集合的约束笛卡儿积) INNER    JOIN 内连接 关联相同的(用于查找关联的信息) FROM C AS c INNER JOIN D AS d ON ...

  10. Entity Framework 的枚举类型

    新增数据模型,新增“实体”之后,新增“枚举类型”,创建Enum值,将“实体”中的列和Enum关联,选中“实体”中的列属性改变类型为Enum名称,生成数据库…… 如下转自:http://item.con ...