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. Ubuntu 下安装adobe reader

    ctrl+alt+t打开终端 wget ftp://ftp.adobe.com/pub/adobe/reader/unix/9.x/9.5.5/enu/AdbeRdr9.5.5-1_i386linux ...

  2. bitbucket git push 项目503失败

    忙活了一天,要把项目push到远程仓库保存: 一直稳定的bitbucket今天突然push不成功了,出了503错误 谷歌了各种原因,还以为是连接出了问题 打开bitbucket State 页面之后, ...

  3. h5移动端百分比

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. ZOJ 2604 Little Brackets DP

    DP: 边界条件:dp[0][j] = 1 递推公式:dp[i][j] = sum{dp[i-k][j] * dp[k-1][j-1] | 0<k≤i} i对括号深度不超过j的,能够唯一表示为( ...

  5. 【Python】学习笔记八:面向对象

    举例 面向对象的合理解释就是:我是人这个类,对象化以后我就是一个个体OLIVER 对象化就是在人这个大类中,将某个人指名道姓,具体到某个人 下面是一个具体的实例一: #!/usr/bin/python ...

  6. Hibernate映射set与List

    1.对于set类型,如果集合中的元素是简单地类型,如字符串型,set使用另外一种映射方式: team类: import java.util.HashSet; import java.util.Set; ...

  7. 异常:Caused by: java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z/Caused by: java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreign

    Spring3.0 + Hibernate3.5:启动服务器报:Caused by: java.lang.NoSuchMethodError: javax.persistence.OneToMany. ...

  8. Mongodb的CRUD

    1.查询 使用db.collection.find()方法进行查询.db.collection.findOne()返回单个文档.mongodb的所有查询操作都是针对单个collection > ...

  9. Android studio 使用心得(六)—android studio 如何加载.so文件

    之前一直没怎么注意,以为.so文件android为像eclipse一样直接加载,但是直到昨天我在android studio上调试公司项目推送消息的时候,才发现,.so文件原来没有加载成功. 可能之前 ...

  10. Unity3D-rigidBody.velocity

    还有半小时就下班了.写一下今天遇到的问题.处理方法以及一些自己的理解.理解的不一定对,还希望大家指正. 今天我做的效果是,hero的移动. 曾经做过用的是transform.Translate(Vec ...