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的。。。

代码:

 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 100000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,tot,a[maxn];
int power(int xx,int yy)
{
ll t=,x=xx,y=yy;
for(;y;y>>=,x=(x*x)%n)
if(y&)t=(t*x)%n;
return t;
}
inline bool check(int m)
{
for1(i,tot)if(power(m,a[i])==)return ;
return ;
}
inline int gcd(int x,int y){return y?gcd(y,x%y):x;}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();
int x=n,y=n;
for2(i,,sqrt(n))
if(x%i==)
{
y=(y/i)*(i-);
while(x%i==)x/=i;
}
if(x!=)y=(y/x)*(x-);
for1(i,y)if(y%i==)a[++tot]=i;tot--;
int cs=read();
while(cs--)
{
int m=read();
if(gcd(m,n)!=)printf("");
else if(check(m))printf("");
else printf("");
}
printf("\n");
return ;
}

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 就行了

代码:

 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 1500000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
struct edga{int go,next;}e[maxn];
int n,tot,head[maxn];
ll s[maxn],f[maxn],w[maxn];
inline void insert(int x,int y)
{
e[++tot].go=y;e[tot].next=head[x];head[x]=tot;
}
void dfs(int x)
{
f[x]=;s[x]=w[x];
for(int i=head[x],y;i;i=e[i].next)
{
dfs(y=e[i].go);
f[x]=((f[x]-w[x]*(s[y]*s[y]%mod))%mod+mod)%mod;
s[x]=(s[x]+s[y])%mod;
}
f[x]=(f[x]+w[x]*(s[x]*s[x]%mod))%mod;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();w[]=read()%mod;
for2(i,,n)insert(read(),i),w[i]=read()%mod;
dfs();
ll ans=;
for1(i,n)ans=(ans+f[i])%mod;
printf("%lld\n",ans);
return ;
}

C.四驱兄弟

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

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

出题人是这样说的:

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

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

代码:

 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1100000000
#define maxn 200000+1000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
typedef map<string,int>::const_iterator cit;
typedef map<string,int>::value_type vt;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
map<string,int>mp;
struct rec{int u,v,w;}e[maxn];
int n,m,tot,a[maxn],fa[maxn];
string s;
inline bool cmp(rec a,rec b)
{
return a.w<b.w;
}
inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();m=read();
for1(i,m)
{
e[i].w=read();
cin>>s;
cit j=mp.find(s);
if(j!=mp.end())e[i].u=j->second;
else
{
mp.insert(mp.begin(),vt(s,++tot));
e[i].u=tot;
}
cin>>s;
j=mp.find(s);
if(j!=mp.end())e[i].v=j->second;
else
{
mp.insert(mp.begin(),vt(s,++tot));
e[i].v=tot;
}
}
sort(e+,e+m+,cmp);
for1(i,tot)fa[i]=i;
int j=;
for1(i,n)
{
while(j<=m&&find(e[j].u)==find(e[j].v))j++;
if(j>m)a[i]=inf;
else
{
a[i]=e[j].w;
fa[find(e[j].u)]=find(e[j].v);
}
j++;
}
for1(i,n)
if(a[i]==inf)printf("INF\n");else printf("%d\n",a[i]);
return ;
}

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. javascript基础笔记学习

    /** * Created by Administrator on 2016/12/26. */ /* var box; alert( typeof box); box是Undefined类型,值是u ...

  2. LeetCode Maximum Product Subarray 解题报告

    LeetCode 新题又更新了.求:最大子数组乘积. https://oj.leetcode.com/problems/maximum-product-subarray/ 题目分析:求一个数组,连续子 ...

  3. jquery中prop()方法和attr()方法的区别(转)

    jquery1.6中新加了一个方法prop(),一直没用过它,官方解释只有一句话:获取在匹配的元素集中的第一个元素的属性值. 官方例举的例子感觉和attr()差不多,也不知道有什么区别,既然有了pro ...

  4. Android实现真正的ViewPager【平滑过渡】+【循环滚动】!!!顺带还有【末页跳转】。

    实现真正的ViewPager[平滑过渡]+[循环滚动]!!!顺带还有[末页跳转]. 首先呢, 我要对网上常见的3种ViewPager的循环滚动方法做个概述.急需看真正实现方法的同志请选择性忽略下面这一 ...

  5. 重学《C#高级编程》(对象与类型)

    昨天重看了下<C#高级编程>里面的对象与类型一章,发现自己有许多遗漏没懂的地方重新弄清楚明白了 先说说什么是对象吧,我个人的感觉是:在编程的世界里,一段程序就是一个事物的处理逻辑,而对象就 ...

  6. JY05-JavsScript-JS基础01

    JavaScript第一天 1.前端三层 HTML   结构层 语义 骨架 css  表现层 审美 衣服 JavsScript 行为层 行为交互 动作 2.转义字符\r\n\t \r return 回 ...

  7. 传输层-TCP

    UDP协议提供了端到端之间的通讯,应用程序只需要在系统中监听一个端口,便可以进行网络通讯.随着计算机网络的发展,计算机网络所承载的业务越来越多,有些业务数据的传输需要具备可靠性,譬如我们在进行在线聊天 ...

  8. 【转】windows消息16进制对应表

    来源:http://blog.sina.com.cn/s/blog_962250db0101d4mj.html windows mobile编程,无论使用eVC还是.net CF,都脱不开window ...

  9. preventDefault() 方法 取消掉与事件关联的默认动作

    前几天写的 响应键盘的图片切换 中, 键盘总是让浏览器滚动,为了取消掉默认的事件,使用了 preventDefault() 方法 定义和用法 preventDefault() 方法取消事件的默认动作. ...

  10. 武汉科技大学ACM :1010: 零起点学算法12——求2个日期之间的天数

    Problem Description 水题 Input 输入2个日期,日期按照年月日,年月日之间用符号-隔开(题目包含多组数据) Output 求出这2个日期之间的天数(不包括自身),每组测试数据一 ...