csp-s模拟9697题解
题面:https://www.cnblogs.com/Juve/articles/11790223.html
96:
刚一看以为是水题,直接等差数列求和就好了,然后发现模数不是质数,还要1e18*1e18,就弃了,看T3,然后看错题了,打了个dij的40分暴力
然后看T1发现我好像会一个叫做慢速乘的东西(颓AlpaCa博客颓到的,现在应该是我的模板的第二个),然后就不用打高精了,
至于模数不是质数,因为答案一定是整数,而我的式子最终要除以4,所以就在乘之前先让它除,然后乘,然后T1就A了,
T2打了个n方暴力,骗到75,rk6还是近几次最好?可能是我太垃圾了。。。
T1:
上面都说过了,不再细说
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
using namespace std;
int x,y,xx,yy,tot=;
int ans=,mod;
int mul(int a,int b,int p){
int res=;
while(b){
if(b&) res=(res+a)%p;
a=(a+a)%p;
b>>=;
}
return res;
}
signed main(){
freopen("sum.in","r",stdin);
freopen("sum.out","w",stdout);
scanf("%lld%lld%lld%lld%lld",&x,&y,&xx,&yy,&mod);
int p=(x+y-),q=(x+yy-),pp=(xx+y-),qq=(xx+yy-);
int xkl1=(p+q+pp+qq),xkl2=(yy-y+),xkl3=(xx-x+);
while(tot<&&xkl1%==){
xkl1/=;
++tot;
}
while(tot<&&xkl2%==){
xkl2/=;
++tot;
}
while(tot<&&xkl3%==){
xkl3/=;
++tot;
}
ans=mul(mul(xkl2,xkl3,mod)%mod,xkl1,mod)%mod;
printf("%lld\n",ans);
return ;
}
T2:
就贪心地扫,二分最大不可行的位置,然而n2logn2复杂度不够优秀,我们倍增缩小二分的区间
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define int long long
#define re register
using namespace std;
inline int read(){
re int x=;re char ch=getchar();
while(ch<''||ch>'') ch=getchar();
while(ch>=''&&ch<=''){
x=(x<<)+(x<<)+ch-'';
ch=getchar();
}
return x;
}
const int MAXN=1e6+;
int n,m,a[MAXN],b[MAXN],ans=;
int staa[MAXN],stab[MAXN],topa,topb;
bool check(int l,int r){
topa=topb=;
for(int i=l;i<=r;++i) staa[++topa]=a[i],stab[++topb]=b[i];
sort(staa+,staa+topa+),sort(stab+,stab+topb+);
int tot=;
for(int i=;i<=topa;++i){
tot+=staa[i]*stab[i];
if(tot>m) return ;
}
return ;
}
int get(int pos){
int poss=;
for(int i=;;++i){
poss=i;
if(pos+(<<i)->n) break;
if(!check(pos,pos+(<<i)-)){
poss=i;
break;
}
}
int l=pos+(<<(poss-))-,r=pos+(<<poss)-;
int res=l;
while(l<=r){
int mid=(l+r)>>;
if(check(pos,mid)) res=max(res,mid),l=mid+;
else r=mid-;
}
return res+;
}
signed main(){
freopen("pair.in","r",stdin);
freopen("pair.out","w",stdout);
n=read(),m=read();
for(re int i=;i<=n;++i) a[i]=read();
for(re int i=;i<=n;++i) b[i]=read();
for(re int i=;i<=n;){
i=get(i);
++ans;
}
printf("%lld\n",ans);
return ;
}
T3:
不太会
97:
T1发现了50分性质就跑了,T2感觉是个sb的dp,但是由于我设的状态,导致他有8个转移,复杂度也只能过70分,T3玄学原因10分暴力都挂了
dp要再复习,dp渣有什么好说的?
发下题解发现我不懂T1的解释,T2又太水了,导致没什么可讲的
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
using namespace std;
const int MAXN=1e5+,mod=1e9+;
int n,a[MAXN],cnt=,ans=,tong[MAXN];
int q_pow(int a,int b,int p){
int res=;
while(b){
if(b&) res=res*a%p;
a=a*a%p;
b>>=;
}
return res;
}
signed main(){
freopen("game.in","r",stdin);
freopen("game.out","w",stdout);
scanf("%lld",&n);
for(int i=;i<=n;++i){
scanf("%lld",&a[i]);
++tong[a[i]];
cnt+=(a[i]==-);
}
ans=(q_pow(,n-,mod)-+mod)%mod;
for(int i=;i<=n;++i){
ans=(ans-q_pow(,tong[i],mod)++mod)%mod;
}
printf("%lld\n",ans);
return ;
}
T2:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
#define re register
using namespace std;
const int mod=1e9+;
int t,n,s,f[][];
signed main(){
freopen("flower.in","r",stdin);
freopen("flower.out","w",stdout);
scanf("%lld",&t);
while(t--){
scanf("%lld%lld",&n,&s);
f[][]=f[][]=s;
f[][]=s*s%mod;
f[][]=(s*s%mod*s%mod-s+mod)%mod;
for(int i=;i<=n;++i){
f[i][]=(f[i-][]*(s-)%mod+f[i-][]*(s-)%mod)%mod;
f[i][]=(f[i-][]*(s-)%mod+f[i-][]*(s-)%mod+f[i-][]*(s-)%mod)%mod;
}
printf("%lld\n",f[n][]%mod);
}
return ;
}
T3:
不会,DEE树钛锯蜡
98:
全程划水,然后T130分暴力又挂了,因为限制的循环层数太小,导致没跑出来
T2一个错误的状压dp水了35分
好吧我现在只会T2
设定01状态,预处理出每个点i,点亮它j秒后那些灯状态会取反,然后倒着转移
话说Yu-shi给我讲的时候我一直理解成正序还说服了自己,我真是太bang了
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,fa[],zt[],s,dp[][],ans=0x3f3f3f3f;
bool f[][(<<)+];
int calc(int state){
int res=;
for(int i=;i<=n;++i){
if(state&(<<(i-))){
res^=(<<(fa[i]-));
}
}
return res;
}
void print(int sta){
for(int i=;i<=n;++i){
if(sta&(<<(i-))) cout<<;
else cout<<;
}
cout<<' ';
for(int i=n;i>=;--i){
if(sta&(<<(i-))) cout<<;
else cout<<;
}
cout<<' ';
}
int main(){
freopen("decoration.in","r",stdin);
freopen("decoration.out","w",stdout);
scanf("%d",&n);
for(int i=;i<=n;++i) scanf("%d",&fa[i]);
for(int i=;i<=n;++i){
scanf("%d",&zt[i]);
s|=(zt[i]<<(i-));
int p=i;
dp[i][]=<<(i-);
p=fa[p];
for(int j=;j<=n;++j,p=fa[p]){
if(p!=) dp[i][j]=dp[i][j-]|(<<(p-));
else dp[i][j]=dp[i][j-];
}
}
f[][]=;
for(int i=;i<=n;++i){
for(int s=;s<(<<n);++s){
f[i][s]|=f[i-][s];
for(int j=;j<=n;++j){
f[i][s^dp[j][i]]|=f[i-][s];
}
}
}
for(int i=;i<=n;++i){
if(f[i][s]){
ans=i;
break;
}
}
printf("%d\n",ans);
return ;
}
csp-s模拟9697题解的更多相关文章
- [CQOI2012]模拟工厂 题解(搜索+贪心)
[CQOI2012]模拟工厂 题解(搜索+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1327574 链接题目地址:洛谷P3161 BZOJ P26 ...
- NOIP第7场模拟赛题解
NOIP模拟赛第7场题解: 题解见:http://www.cqoi.net:2012/JudgeOnline/problemset.php?page=13 题号为2221-2224. 1.car 边界 ...
- 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程
数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...
- HGOI NOIP模拟4 题解
NOIP国庆模拟赛Day5 题解 T1 马里奥 题目描述 马里奥将要参加 NOIP 了,他现在在一片大陆上,这个大陆上有着许多浮空岛,并且其中一座浮空岛上有一个传送门,马里奥想要到达传送门从而前往 N ...
- 10.8 wtx模拟题题解
填坑 orz w_x_c_q w_x_c_q的模拟赛(150pts,炸了) money 题目背景: 王小呆又陷入自己的梦里.(活在梦里...) 题目描述: 王小呆是一个有梦想的小菜鸡,那就是赚好多好多 ...
- [NOIP模拟13]题解
A.矩阵游戏 其实挺水的? 考场上根本没有管出题人的疯狂暗示(诶这出题人有毛病吧这么简单的东西写一大堆柿子),而且推公式能力近乎没有,所以死掉了. 很显然乘法有交换率结合率所以操作顺序对最终结果没什么 ...
- 「题解」NOIP模拟测试题解乱写II(36)
毕竟考得太频繁了于是不可能每次考试都写题解.(我解释个什么劲啊又没有人看) 甚至有的题目都没有改掉.跑过来写题解一方面是总结,另一方面也是放松了. NOIP模拟测试36 T1字符 这题我完全懵逼了.就 ...
- 【洛谷】xht模拟赛 题解
前言 大家期待已久并没有的题解终于来啦~ 这次的T1和HAOI2016撞题了...深表歉意...表示自己真的不知情... 天下的水题总是水得相似,神题各有各的神法.--<安娜·卡列妮娜> ...
- 10.9 guz模拟题题解
感谢@guz 顾z的题题解 考试共三道题,其中 第一题help共10个测试点,时间限制为 1000ms,空间限制为 256MB. 第二题escape共20个测试点,时间限制为1000ms2000ms, ...
随机推荐
- keep-alive用法及(activated,deactivated生命周期)
<template> <div id="app"> <!-- <img src="./assets/logo.png"> ...
- Flask理论基础(一)视图函数和URL反转函数(url_for)
一.视图函数 1.1 基本用法试图函数是 app.route 或者 bp.route(蓝图)装饰器装饰的函数.该函数实现了对URL路径的转换,也就是路由功能,例如下面代码定义了默认url ‘/’ 和‘ ...
- awk与sed命令面试题整理
1.sed命令123abc456456def123567abc789789def567要求输出:456ABC123123DEF456789ABC567567DEF789答案:sed -r -i 's# ...
- WordPress建站要怎样选择适合自己的主机
目前很多大中小的网站都在使用WordPress进行建站,因为互联网站长都知道WordPress建站是很方便的,简洁的界面,栅格化管理风格,深受互联网站长的喜爱. 现在支持WordPress建站的主机商 ...
- Centos 14: problem making ssl connection
在执行 yum 命令时,会提示 Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Could not g ...
- toLocaleString 日期
new Date().toLocaleString()"2018/5/3 下午3:08:48"
- 使用Fiddler抓取手机包
配置Fiddler 设置抓取HTTPS包 允许为外部连接 配置移动端 移动端需要能够连接到主机做代理, 设置移动端的网络, 端口为Fiddler的端口, 然后给移动端安装证书, 访问主机名+代理端口号 ...
- swiper缩略图active切换失灵的解决思路
报错信息:Cannot read property ‘indexOf’ of undefined swiper. 来源是swiper.min.js,首先检查自己写的js配置是否有误,没有就调试插件源代 ...
- Json数据交换一Gson
Gson 是 Google 提供的用来在 Java 对象和 JSON 数据之间进行映射的 Java 类库.可以将一个 JSON 字符串转成一个 Java 对象,或者反过来. 添加依赖 <depe ...
- 通过jquery获取页面信息
获取浏览器显示区域(可视区域)的高度 : $(window).height(); 获取浏览器显示区域(可视区域)的宽度 :$(window).width(); 获取页面的文档高度 $(document ...