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

犯了sb错误。。。。t2的longlong的mul我没分别开modQAQ爆了两个点。。。可是就算开了我也是230.。。在此orz神犇zyfAK爷orzzzz还有jiryAK爷orzzzz

upd:成绩出来了。。。。。。。。。。我110滚粗。。。。。。。。。。。。。。。。果然太弱吗。。。。。。。。。。。。。。。t3 喜闻乐见的ce了。。。因为今天刚装了g++ 4.9.。。sad stroy。。它不提示cmp那里引用要加const啊!!!!

然后尽管改了这里还有地方写挫了。。。。。。。。。我的并查集写得太快没有写路径压缩。。。。。。。。。。sad,,调了n久。。。

蒟蒻的生存史就这样了。。。。。。sad。。

t1:九九归一

唯一没能a的就是这题了。。。t1啊。。t1我都搞不出来。。。

暴力30分QAQ

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } int md, n;
int gcd(int a, int b) { return b?a:gcd(b, a%b); }
int main() {
read(md); read(n);
int phi=md, t=md, sqr=sqrt(md+0.5);
for1(i, 2, sqr) if(t%i==0) {
phi=phi/i*(i-1);
while(t%i==0) t/=i;
}
if(t>1) phi=phi/t*(t-1);
rep(i, n) {
int a=getint(), len=1; t=a;
//if(gcd(a, n)!=1) { printf("0"); continue; }
if(a==0) { printf("0"); continue; }
while((t%md)!=1) {
t=(t*a)%md, ++len;
if(len>phi) break;
}
printf("%d", len==phi);
}
return 0;
}

t2:LCA的统计

这题找找规律会发现。

节点x可以得到的ans有

w[i]*sum{sum[j]*sum[other]},然后乘上自己然后加上自己到子树节点的sum[x]*2即可。这里的longlong我不想说了QAQ自己弱。。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } typedef unsigned long long ll;
const int N=100005, md=1000000007;
int ihead[N], cnt, n;
ll w[N], ans, sum[N];
struct ED { int to, next; }e[N<<1];
void add(int u, int v) {
e[++cnt].next=ihead[u]; ihead[u]=cnt; e[cnt].to=v;
e[++cnt].next=ihead[v]; ihead[v]=cnt; e[cnt].to=u;
}
inline ll mul(ll a, ll b) { return ((a%md)*(b%md))%md; } //我sb了。。这里没分开md
void dfs(int x, int fa) {
sum[x]=w[x];
int y;
for(int i=ihead[x]; i; i=e[i].next) if(fa!=(y=e[i].to)) {
dfs(y, x); sum[x]+=sum[y];
}
ll s=0;
for(int i=ihead[x]; i; i=e[i].next) if(fa!=(y=e[i].to)) {
ll other=(((sum[x]-sum[y]+md)%md)-w[x]+md)%md;
s=(s+mul(other, sum[y]))%md;
}
ans=(ans+mul(s, w[x]))%md;
ans=(ans+mul(2, mul(w[x], mul(w[x], (sum[x]-w[x]+md)%md))))%md;
ans=(ans+mul(mul(w[x], w[x]), w[x]))%md;
}
int main() {
read(n); read(w[1]);
for1(i, 2, n) { int v=getint(); read(w[i]); add(v, i); }
dfs(1, 0);
printf("%lld", ans);
return 0;
}

t3:四驱兄弟

最裸的一题了,直接mst。

发现不能有环果断是生成树

发现有排名,果断最小生成树。

没了。。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=100005;
int ihead[N], cnt, n, m, p[N], tot;
struct dat { int x, y, w; }e[N];
map<string, int> mp;
int ifind(int x) { return x==p[x]?x:ifind(p[x]); }
int cmp(dat& a, dat& b) { return a.w<b.w; }
int id(char *ch) {
string s(ch);
if(mp[s]) return mp[s];
mp[s]=++tot;
return mp[s];
}
int main() {
read(n); read(m);
string s; char ch[10];
for1(i, 1, m) {
read(e[i].w);
scanf("%s", ch); e[i].x=id(ch);
scanf("%s", ch); e[i].y=id(ch);
}
for1(i, 1, tot) p[i]=i;
sort(e+1, e+1+m, cmp);
int num=0;
for1(i, 1, m) {
int fx=ifind(e[i].x), fy=ifind(e[i].y);
if(fx!=fy) {
p[fy]=fx;
++num;
if(num>n) break;
printf("%d\n", e[i].w);
}
}
for1(i, num+1, n) puts("INF");
return 0;
}

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

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

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

  2. 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 ...

  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. liunx系统安装tomcat的方法

    安装tomcat前需要先安装jdk,安装jdk的方法参考我的上一篇文章:liunx系统安装jdk的方法 1.下载tomcat 下载地址:http://tomcat.apache.org/downloa ...

  2. Spring官方下载地址

    改版后的Spring官方网站下载地址找不到了,汗~~ 可以通过该链接下载对应的包:http://repo.spring.io/milestone/org/springframework/ Spring ...

  3. LoadRunner测试ajaxweb程序攻略

    用loadrunner测试WEB程序的时候总是会碰到AJAX或者ActiveX实现的功能,而通常这些功能会包含很多客户端函数(一般为JavaScript).我们该如何处理?如果从功能实现的角度去考虑这 ...

  4. ES6 数值扩展

    1.Number.isNan 和 Number.isFinite Number.isNaN()用来检查一个值是否为NaN Number.isNaN(NaN) // true Number.isNaN( ...

  5. servlet 简单filter避免中文乱码等

    Filter是个servlet中的接口,servlet内部实现了利用Filter来过滤请求.   可以在filter中根据条件决定是否调用chain.doFilter(request,response ...

  6. 用squid配置代理服务器(基于Ubuntu Server 12.04)

    怀揣着为中小企业量身定做一整套开源软件解决方案的梦想开始了一个网站的搭建.http://osssme.org/ 1. 安装squid $sudo apt-get install squid -y 注: ...

  7. Python 多行注释

    Python 使用" # ” 进行单行注释,本身不带多行注释. 但在编译器 PyCharm 中,可以用以下方法注释多行代码: 1.“选中一段要注释的代码——>Ctrl+ / ” 即可注 ...

  8. 【Shiro】Apache Shiro架构之权限认证(Authorization)

    Shiro系列文章: [Shiro]Apache Shiro架构之身份认证(Authentication) [Shiro]Apache Shiro架构之集成web [Shiro]Apache Shir ...

  9. 【转】C#播放H264裸码流

    原文地址:https://www.cnblogs.com/cangyue080180/p/5873351.html 要播放H264裸码流,可以分拆为以下三个工作: 1.解码H264裸码流获取YUV数据 ...

  10. Request to https://bower.herokuapp.com failed with 502

    bower 版本过低,需要升级为最新bower版本, 如果升级版本后依然无法使用,更改.bowerrc配置,如下所示 { "directory": "bower_comp ...