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 ...
随机推荐
- ssh远程连接不上ubuntu
问题描述: 1.ubuntu安装了openssh-server,启动了ssh 守护进程,使用端口22 2.在本机可以 ssh 127.0.0.1 连接 3.通过ssh远程(比如用putty 或crt) ...
- 【科研论文】W5100在远程电力质量监测设备中的应用
摘要: 针对传统电力质量监测方法实时性.多参数测试性能较差的缺点,提出了将以太网接入技术与电能采集相结合进行电力质量现场和远程在线监测的设计方案.硬件设计采用微控制器STM32FI03和以太网控制芯片 ...
- Android 适配
给定字体大小适配时应按照12sp,14sp,18sp,22sp 这几种字体的大小设置,以避免字体大小混乱12sp以上大小,14sp 18sp 22sp 字体首选大小,不要使用奇数.小数,否则会造成精度 ...
- ListView列表拖拽排序
ListView列表拖拽排序能够參考Android源代码下的Music播放列表,他是能够拖拽的,源代码在[packages/apps/Music下的TouchInterceptor.java下]. 首 ...
- iPhone 各版本屏幕分辨率
参考:http://www.paintcodeapp.com/news/iphone-6-screens-demystified
- 对相同id的input框的循环判断
$("input[id=sl]").each(function(){ alert(10); });
- 单线程与多线程的简单示例(以Windows服务发短信为示例)
单线程示例: public delegate void SM(); SM sm = new SM(() => { while (true) ...
- nginx轮询配置详解
nginx轮询配置详解... Nginx配置文件详细说明转载
- MySQL查询执行的基础
当希望MySQL能够以更高的性能运行查询时,最好的办法就是弄清楚MySQL是如何优化和执行查询的.一旦理解这一点,很多查询优化实际上就是遵循一些原则让优化器能够按照预想的合理的方式运行. 换句话说,是 ...
- Spring4.0学习笔记(5) —— 管理bean的生命周期
Spring IOC 容器可以管理Bean的生命周期,Spring允许在Bean生命周期的特定点执行定制的任务 Spring IOC 容器对Bean的生命周期进行管理的过程: 1.通过构造器或工厂方法 ...