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. Spark1.0.0 history server 配置

    在执行Spark应用程序的时候,driver会提供一个webUI给出应用程序的执行信息.可是该webUI随着应用程序的完毕而关闭port,也就是说,Spark应用程序执行完后,将无法查看应用程序的历史 ...

  2. IIS 之 Asp.Net项目内部运行详解

    我们都知道,当用户在浏览器地址栏中输入网址时,该请求会被IIS服务器捕获,如果是请求的是静态页面则由IIS本身处理并直接返回客户端:如果是动态页(*.aspx),通过一系列的前期的处理来到 .NET ...

  3. ppm图像格式

    http://blog.csdn.net/r91987/article/details/5435328 PPM文件格式分三种: 1. PPM灰度文件     文件头由3行文本组成,可由fgets读出 ...

  4. 重构wm_concat,采用clob做为存储容器

    --Type CREATE OR REPLACE TYPE zh_concat_im AUTHID CURRENT_USER AS OBJECT ( CURR_STR clob, STATIC FUN ...

  5. 学 Vim 时希望早点知道的建议

    来自wechat 从 2009 年开始,我就一直把 Vim 当做我的主要(唯一)文本编辑器.在过去的这些年,我学到了很多好用的 Vim 技巧,它们令我感觉相见恨晚,因为它们极大地提高了我的文本编辑效率 ...

  6. 【DB2】查询上月末、上年末、上年同期等信息

    此处以20180612为例子 想得到上年末.上年同期.上月末这些时间点,只需要记住函数ADD_MONTHS.LAST_DAY.ADD_YEARS这些函数即可. 上年末 SELECT SUBSTR(TO ...

  7. LNMP环境搭建——MySQL篇

    The world's most popular open source database 1.Install MySQL root@kallen:~# apt-get install mysql-s ...

  8. ssh2 三大框架整合

    提示:eclipse环境.工程环境.tomcat环境的jdk保持一致 1.新建一个工程,把工程的编码为utf-8 2.把jsp的编码形式改成utf-8 3.把jar包放入到lib下           ...

  9. flashback database(drop tablespace)

    1.首先记录时间 select to_char(systimestamp,'yyyy-mm-dd HH24:MI:SS') from dual;--2014-04-25 13:55:48 查看表sel ...

  10. HTTP协议发展历史

    一.HTTP 0.9版本 1991年发布0.9版本,只有一个 GET 命令. 例如:GET /index.html   表示浏览器只能接收返回 html 格式的字符串:服务器发送完毕就关闭tcp链接. ...