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. Afinal的jar包进行代码混淆出错

    今天用到了代码混淆,混淆过后APP不能够运行,老报错,由于项目中只用了Afinal的第三方库,于是按照网上给出的答案为了不混淆Afinal的jar包,在配置文件中写入了下面的语句: -libraryj ...

  2. Solidworks如何设置零件材料,如何评估零件质量

    右击材质,然后编辑材料,在弹出菜单中在Solidworks materials中选择零件材料(一般钢或者铁,注意质量密度是否跟你需要的一致),完成之后点击应用和关闭   在评估-质量属性中可以看到当前 ...

  3. 算法笔记_079:蓝桥杯练习 区间k大数查询(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 给定一个序列,每次询问序列中第l个数到第r个数中第K大的数是哪个. 输入格式 第一行包含一个数n,表示序列长度. 第二行包含n个正整数,表 ...

  4. 对象的序列化(Serialization)

    一.什么是序列化 序列化表示将一个对象转换成可存储或可传输的状态,序列化后对象可以在网络上进行传输,也可以存储到本地.对象的寿命通常随着生成该对象的程序的终止而终止.有时候,可能需要将对象的状态保存下 ...

  5. 安卓Camera APP

    一.Camera package android.hardware            该类用于设定图像捕获设置,开启/关闭预览,抓拍图片以及获取帧用于编码视频.这个类是Camera服务的客户端,用 ...

  6. 基于layui的框架模版,采用模块化设计,接口分离,组件化思想

    代码地址如下:http://www.demodashi.com/demo/13362.html 1. 准备工作 编辑器vscode,需要安装liveServer插件在前端开启静态服务器 或者使用hbu ...

  7. glassfish3操作命令

    glassfish3操作命令   启动:C:\Java\glassfish\bin>asadmin start-domain domain1 停止:C:\Java\glassfish\bin&g ...

  8. jQuery源代码学习:经常使用正則表達式

    转载自:http://nuysoft.iteye.com/blog/1217898 经常使用的数字正则(严格匹配) 正则 含义 ^[1-9]\d*$ 匹配正整数 ^-[1-9]\d*$ 匹配负整数 ^ ...

  9. FZU 2087 统计树边【MST相关】

     Problem 2087 统计树边 Accept: 212    Submit: 651 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Prob ...

  10. Sql添加测试数据

    --建测试表 CREATE TABLE T_UserInfo ( Userid varchar(20),  UserName varchar(20), RegTime datetime, Tel va ...