CH Round #55 - Streaming #6 (NOIP模拟赛day2)(被虐哭)
犯了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)(被虐哭)的更多相关文章
- CH Round #55 - Streaming #6 (NOIP模拟赛day2)
A.九九归一 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2355%20-%20Streaming%20%236%20(NOIP模拟赛day2)/九九归一 题 ...
- 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 ...
- CH Round #49 - Streaming #4 (NOIP模拟赛Day2)
A.二叉树的的根 题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模 ...
- CH Round #58 - OrzCC杯noip模拟赛day2
A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...
- CH Round #48 - Streaming #3 (NOIP模拟赛Day1)
A.数三角形 题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛D ...
- 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题, ...
- CH Round #54 - Streaming #5 (NOIP模拟赛Day1)解题报告
最近参加了很多CH上的比赛呢~Rating--了..题目各种跪烂.各种膜拜大神OTZZZ T1珠 描述 萌蛋有n颗珠子,每一颗珠子都写有一个数字.萌蛋把它们用线串成了环.我们称一个数字串是有趣的,当且 ...
- 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 ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
随机推荐
- ASP.NET MVC & Web API Brief Introduction
Pure Web Service(ASMX): Starting back in 2002 with the original release of .NET, a developer could f ...
- 获取ping的最短、最长、平均时间
# -*- coding: utf-8 -*- import osimport rep = os.popen('ping 120.26.77.101') out = p.read()regex = r ...
- 【Statistics】CAP曲线
功能描述 CAP曲线(Cumulative Accuracy Profile)/Power Curve(准确率/AR)是描述整个评级结果下,累计违约客户比例与累计客户比例的关系. 在完美的模型下,CA ...
- windows下更换jdk运行当前jar包处理命令一则
可在文本文档中新建以下内容 set JAVA_HOME=C:\jdk1.7.0_67set CLASSPATH=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOMe%\lib\too ...
- Name与x:Name的关系
小序: 如果想用Google搜包含冒号的内容怎么办?比如我想搜x:Name这个字符串…… 原来,应该是这样——x::Name 这世道,连搜索也要加转义,全民程序员,要不要人活了? 正文: ...
- oracle expdp导入时 提示“ORA-39002: 操作无效 ORA-39070: 无法打开日志文件 ”
1.导出数据库的时候报错 expdp zz/zz@orcl directory=exp_dp dumpfile=zz_20170520.dump logfile=zz_20170520.log 2 ...
- ASP.NET MVC使用IoC
也许你会问ASP.NET MVC为什么会爱上IoC? 相爱的理由常常很简单,就像一首歌中所唱——“只为相遇那一个眼神”. 而ASP.NET MVC爱上IoC只为IoC能实现MVC控制器的依赖注入. 下 ...
- ubuntu12.04打开某一个已安装的软件的方法
1.快捷键win+A,里面显示已安装的软件 2.打开左上角的dash home,即ubuntu标志图,输入想要打开的软件 还有其它方法,探索中... .
- Oracle Restart能够用来给Oracle GoldenGate 做 High Availability 使用么?
Oracle Restart能够用来给Oracle GoldenGate 做 High Availability 使用么? 来源于: Can Oracle Restart be used with ...
- Atitit.数据操作dsl 的设计 ---linq 方案
Atitit.数据操作dsl 的设计 ---linq 方案 1.1. sql与api方式1 1.2. Linq方案与stream方案的选择,1 1.3. 前缀表达式 vs 中缀表达式1 1.4. 要不 ...