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题,把原串复制一边接到后面然后来回扫两遍即可。
sb题还不能A,我是大sb,数组开小+只扫一遍=90
幸亏出题人数据良心T_T
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 200000+1000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,f[maxn];
string s;
bool flag=;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin>>s;
s=s+s;
n=s.length()>>;
memset(f,,sizeof(f));
for0(i,*n-)
if(s[i]=='')f[i]=,flag=;
else if(s[i]=='')
{
if(i==)continue;
f[i]=f[i-]+;
}
int ans=;
for0(i,*n-)ans=max(ans,min(f[i],n));
memset(f,,sizeof(f));
for3(i,*n-,)
if(s[i]=='')f[i]=,flag=;
else if(s[i]=='')
{
if(i==)continue;
f[i]=f[i+]+;
}
for0(i,*n-)ans=max(ans,min(f[i],n));
if(!flag)printf("TvT\n");
else
{
printf("");
for1(i,ans-)printf("");
printf("\n");
}
return ;
}
B.兔农
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2354%20-%20Streaming%20%235%20(NOIP模拟赛Day1)/免农
题解:刚开始看见题目给吓尿了,莫非真是noi2011的兔农?
后来想了想如何骗分:
1)k%p==0 直接输出0
2)n<=100W 暴力
3)貌似 k 是偶数直接上快速幂
4)好像 只要减少1只之后就不会减少了 break之后上快速幂
结果在最后1分钟交了就A了。。。rp。。。
而且这居然就是正解。。。乱搞啊。。。
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 500+100
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
ll n,k,p;
ll power(ll x,ll y)
{
ll t=;
for(;y;y>>=,x=(x*x)%p)
if(y&)t=(t*x)%p;
return t;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();k=read();p=read();
if(k%==)printf("%lld\n",power(,n+));
else if(k%p==)printf("0\n");
else if(n<=)
{
ll x=%k,y=%p;
for(ll i=;i<=n;i++)
{
x=(x+x)%k;
y=(y+y)%p;
if(x==)x=,y=(y-+p)%p;
}
printf("%lld\n",y);
}
else
{
ll x=%k,y=%p,i=;
for(i=;i<=n;i++)
{
x=(x+x)%k;
y=(y+y)%p;
if(x==){x=;y=(y-+p)%p;break;}
}
printf("%lld\n",power(,n-i)*y%p);
}
return ;
}
C.高维网络
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2354%20-%20Streaming%20%235%20(NOIP模拟赛Day1)/高维网络
题解:首先从n维空间中一个点到另一个点(某一维不能往回走)的方案数就是一个多重集合的排列数。
然后问题就转化成了一个容斥原理。暴力容斥貌似能得80?让我们考虑满分算法:
我当时不知怎么想的就yy出了和题解一样的方法。。。
我的代码是这样的:
int l=,r=;q[]=;g[]=-;
while(l<r)
{
int x=q[++l];
for1(i,m+)
if(f[x][i])
{
inp[i]--;
g[i]-=mul(g[x],f[x][i]);
g[i]=(g[i]%mod+mod)%mod;
if(!inp[i])q[++r]=i;
}
}
(mul是一个乘法函数,我不想都开long long 又怕爆int so。。。)
f[x][i]表示 x 到 i 的路径条数
貌似根据容斥原理很好懂?(其实是我说不清楚。。。)
我还是搬运题解吧:
设g[i]表示从点A到点i,不经过任何一个被破坏的点的路线条数。
设f[i][j]表示从点 i 到点 j 可以经过任意个被破坏的点的路线条数,那么
那么g[i]= f[A][i]−从点A到点 i ,经过了至少一个被破坏的点的路线条数。
枚举经过的第一个被破坏的点,那么
那么g[i]= f[A][i]-sigma(g[x]*f[x][i]) (x可达i)
最后 g[B]就是答案。
orzzzz
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 500+100
#define maxm 10000000+10
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,m,b[maxn][maxn],mx,fac[maxm],g[maxn],inp[maxn],q[maxn],f[maxn][maxn];
inline bool check(int x,int y)
{
for1(i,n)if(b[x][i]>b[y][i])return ;
return ;
}
ll power(ll x,ll y)
{
ll t=;
for(;y;y>>=,x=(x*x)%mod)
if(y&)t=(t*x)%mod;
return t;
}
inline int mul(int x,int y)
{
ll xx=x,yy=y;
return (xx*yy)%mod;
}
inline ll dist(int x,int y)
{
ll t1=,t2=;
for1(i,n)
{
t1+=b[y][i]-b[x][i];
t2=mul(t2,fac[b[y][i]-b[x][i]]);
}
t1=fac[t1];
return t1*power(t2,mod-)%mod;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();m=read();
for1(i,n)
{
b[m+][i]=read();
if(b[m+][i]>mx)mx=b[m+][i];
}
mx*=n;
for1(i,m)for1(j,n)b[i][j]=read();
fac[]=;
for1(i,mx)fac[i]=mul(fac[i-],i);
for0(i,m)
for0(j,m+)
if(i!=j)
if(check(i,j))f[i][j]=dist(i,j),inp[j]++;
int l=,r=;q[]=;g[]=-;
while(l<r)
{
int x=q[++l];
for1(i,m+)
if(f[x][i])
{
inp[i]--;
g[i]-=mul(g[x],f[x][i]);
g[i]=(g[i]%mod+mod)%mod;
if(!inp[i])q[++r]=i;
}
}
printf("%d",g[m+]);
return ;
}
没AK感觉有点儿遗憾,不过RP已经是爆棚了。。。
CH Round #54 - Streaming #5 (NOIP模拟赛Day1)的更多相关文章
- 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 #48 - Streaming #3 (NOIP模拟赛Day1)
A.数三角形 题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛D ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
- 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...
- 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 #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 ...
随机推荐
- [置顶] vb报表的设计
敲机房收费系统,最难的部分应该就是关于报表的部分了.相对于学生信息管理系统,报表是新内容,在vb中添加报表需要添加第三方控件,首先我们要下载水晶报表,下面就向大家展示一下我设计报表的步骤(我用的新版本 ...
- Robotium -- AndroidUI优化工具HierarchyViewer
为什么使用HierarchyViewer 不合理的布局会使我们的应用程序UI性能变慢,HierarchyViewer能够可视化的角度直观地获得UI布局设计结构和各种属性的信息,帮助我们优化布局设计.H ...
- Android项目实战--手机卫士18--读取用户的短信内容以及短信备份
我们今天要说的就是我们手机卫士里面的高级工具里面的短信备份功能啦,其实这个软件备份的功能也很简单,就是把用户的短信读出来,然后写到一个xml或者数据库里面, 但我们这里的是读取到xml里面的. 首先我 ...
- [Javascript] Array methods in depth - slice
Array slice creates a shallow copy of an array. In this lesson we cover, in detail, exactly what a ' ...
- 编译lua版本问题
Compile++ thumb : game_shared <= main.cppjni/hellocpp/main.cpp: In function 'void Java_org_cocos ...
- 多表关联查询(ORACLE版)
前言:这几天学习oracle,把自己对于关联查询的理解,记录下.如有错误请指正! 交叉连接: 交欢连接又称为“笛卡儿积连接”,是两个或多个表之间的无条件连接.一个表中所有的记录与其它表的所有的记录进行 ...
- C#正则怎么判断字符串中是否有汉字
Regex r = new Regex(".*[\\u4e00-\\u9faf].*");r.IsMatch(username)
- linux查询当前进程数的命令
$command = "ps aux | grep 'zb_insure/get_order_info_from_queue.php' | grep -v 'grep' | grep - ...
- c - 统计字符串"字母,空格,数字,其他字符"的个数和行数.
#include <stdio.h> #include <ctype.h> using namespace std; /* 题目:输入一行字符,分别统计出其中英文字母.空格.数 ...
- MySQL查看数据库大小、表大小和最后修改时间
查看数据库表基本信息. select * from information_schema.TABLES where information_schema.TABLES.TABLE_SCHEMA = ' ...