題面:https://www.cnblogs.com/Juve/articles/11790223.htmlhtml
96:ios
剛一看覺得是水題,直接等差數列求和就行了,而後發現模數不是質數,還要1e18*1e18,就棄了,看T3,而後看錯題了,打了個dij的40分暴力ide
而後看T1發現我好像會一個叫作慢速乘的東西(頹AlpaCa博客頹到的,如今應該是個人模板的第二個),而後就不用打高精了,spa
至於模數不是質數,由於答案必定是整數,而個人式子最終要除以4,因此就在乘以前先讓它除,而後乘,而後T1就A了,3d
T2打了個n方暴力,騙到75,rk6仍是近幾回最好?多是我太垃圾了。。。code
T1:orm
上面都說過了,再也不細說htm
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #define int long long 6 using namespace std; 7 int x,y,xx,yy,tot=0; 8 int ans=0,mod; 9 int mul(int a,int b,int p){ 10 int res=0; 11 while(b){ 12 if(b&1) res=(res+a)%p; 13 a=(a+a)%p; 14 b>>=1; 15 } 16 return res; 17 } 18 signed main(){ 19 freopen("sum.in","r",stdin); 20 freopen("sum.out","w",stdout); 21 scanf("%lld%lld%lld%lld%lld",&x,&y,&xx,&yy,&mod); 22 int p=(x+y-1),q=(x+yy-1),pp=(xx+y-1),qq=(xx+yy-1); 23 int xkl1=(p+q+pp+qq),xkl2=(yy-y+1),xkl3=(xx-x+1); 24 while(tot<2&&xkl1%2==0){ 25 xkl1/=2; 26 ++tot; 27 } 28 while(tot<2&&xkl2%2==0){ 29 xkl2/=2; 30 ++tot; 31 } 32 while(tot<2&&xkl3%2==0){ 33 xkl3/=2; 34 ++tot; 35 } 36 ans=mul(mul(xkl2,xkl3,mod)%mod,xkl1,mod)%mod; 37 printf("%lld\n",ans); 38 return 0; 39 }
T2:blog
就貪心地掃,二分最大不可行的位置,然而n2logn2複雜度不夠優秀,咱們倍增縮小二分的區間get
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<vector> 6 #define int long long 7 #define re register 8 using namespace std; 9 inline int read(){ 10 re int x=0;re char ch=getchar(); 11 while(ch<'0'||ch>'9') ch=getchar(); 12 while(ch>='0'&&ch<='9'){ 13 x=(x<<3)+(x<<1)+ch-'0'; 14 ch=getchar(); 15 } 16 return x; 17 } 18 const int MAXN=1e6+5; 19 int n,m,a[MAXN],b[MAXN],ans=0; 20 int staa[MAXN],stab[MAXN],topa,topb; 21 bool check(int l,int r){ 22 topa=topb=0; 23 for(int i=l;i<=r;++i) staa[++topa]=a[i],stab[++topb]=b[i]; 24 sort(staa+1,staa+topa+1),sort(stab+1,stab+topb+1); 25 int tot=0; 26 for(int i=1;i<=topa;++i){ 27 tot+=staa[i]*stab[i]; 28 if(tot>m) return 0; 29 } 30 return 1; 31 } 32 int get(int pos){ 33 int poss=1; 34 for(int i=1;;++i){ 35 poss=i; 36 if(pos+(1<<i)-1>n) break; 37 if(!check(pos,pos+(1<<i)-1)){ 38 poss=i; 39 break; 40 } 41 } 42 int l=pos+(1<<(poss-1))-1,r=pos+(1<<poss)-1; 43 int res=l; 44 while(l<=r){ 45 int mid=(l+r)>>1; 46 if(check(pos,mid)) res=max(res,mid),l=mid+1; 47 else r=mid-1; 48 } 49 return res+1; 50 } 51 signed main(){ 52 freopen("pair.in","r",stdin); 53 freopen("pair.out","w",stdout); 54 n=read(),m=read(); 55 for(re int i=1;i<=n;++i) a[i]=read(); 56 for(re int i=1;i<=n;++i) b[i]=read(); 57 for(re int i=1;i<=n;){ 58 i=get(i); 59 ++ans; 60 } 61 printf("%lld\n",ans); 62 return 0; 63 }
T3:
不太會
97:
T1發現了50分性質就跑了,T2感受是個sb的dp,可是因爲我設的狀態,致使他有8個轉移,複雜度也只能過70分,T3玄學緣由10分暴力都掛了
dp要再複習,dp渣有什麼好說的?
發下題解發現我不懂T1的解釋,T2又太水了,致使沒什麼可講的
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #define int long long 6 using namespace std; 7 const int MAXN=1e5+5,mod=1e9+7; 8 int n,a[MAXN],cnt=0,ans=0,tong[MAXN]; 9 int q_pow(int a,int b,int p){ 10 int res=1; 11 while(b){ 12 if(b&1) res=res*a%p; 13 a=a*a%p; 14 b>>=1; 15 } 16 return res; 17 } 18 signed main(){ 19 freopen("game.in","r",stdin); 20 freopen("game.out","w",stdout); 21 scanf("%lld",&n); 22 for(int i=1;i<=n;++i){ 23 scanf("%lld",&a[i]); 24 ++tong[a[i]]; 25 cnt+=(a[i]==-1); 26 } 27 ans=(q_pow(2,n-1,mod)-1+mod)%mod; 28 for(int i=1;i<=n;++i){ 29 ans=(ans-q_pow(2,tong[i],mod)+1+mod)%mod; 30 } 31 printf("%lld\n",ans); 32 return 0; 33 }
T2:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #define int long long 6 #define re register 7 using namespace std; 8 const int mod=1e9+7; 9 int t,n,s,f[100005][2]; 10 signed main(){ 11 freopen("flower.in","r",stdin); 12 freopen("flower.out","w",stdout); 13 scanf("%lld",&t); 14 while(t--){ 15 scanf("%lld%lld",&n,&s); 16 f[1][0]=f[3][1]=s; 17 f[2][0]=s*s%mod; 18 f[3][0]=(s*s%mod*s%mod-s+mod)%mod; 19 for(int i=4;i<=n;++i){ 20 f[i][0]=(f[i-1][0]*(s-1)%mod+f[i-2][0]*(s-1)%mod)%mod; 21 f[i][1]=(f[i-1][1]*(s-1)%mod+f[i-2][1]*(s-1)%mod+f[i-3][0]*(s-1)%mod)%mod; 22 } 23 printf("%lld\n",f[n][1]%mod); 24 } 25 return 0; 26 }
T3:
不會,DEE樹鈦鋸蠟
98:
全程划水,而後T130分暴力又掛了,由於限制的循環層數過小,致使沒跑出來
T2一個錯誤的狀壓dp水了35分
好吧我如今只會T2
設定01狀態,預處理出每一個點i,點亮它j秒後那些燈狀態會取反,而後倒着轉移
話說Yu-shi給我講的時候我一直理解成正序還說服了本身,我真是太bang了
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int n,fa[20],zt[20],s,dp[17][17],ans=0x3f3f3f3f; 7 bool f[17][(1<<16)+5]; 8 int calc(int state){ 9 int res=0; 10 for(int i=2;i<=n;++i){ 11 if(state&(1<<(i-1))){ 12 res^=(1<<(fa[i]-1)); 13 } 14 } 15 return res; 16 } 17 void print(int sta){ 18 for(int i=1;i<=n;++i){ 19 if(sta&(1<<(i-1))) cout<<1; 20 else cout<<0; 21 } 22 cout<<' '; 23 for(int i=n;i>=1;--i){ 24 if(sta&(1<<(i-1))) cout<<1; 25 else cout<<0; 26 } 27 cout<<' '; 28 } 29 int main(){ 30 freopen("decoration.in","r",stdin); 31 freopen("decoration.out","w",stdout); 32 scanf("%d",&n); 33 for(int i=2;i<=n;++i) scanf("%d",&fa[i]); 34 for(int i=1;i<=n;++i){ 35 scanf("%d",&zt[i]); 36 s|=(zt[i]<<(i-1)); 37 int p=i; 38 dp[i][1]=1<<(i-1); 39 p=fa[p]; 40 for(int j=2;j<=n;++j,p=fa[p]){ 41 if(p!=0) dp[i][j]=dp[i][j-1]|(1<<(p-1)); 42 else dp[i][j]=dp[i][j-1]; 43 } 44 } 45 f[0][0]=1; 46 for(int i=1;i<=n;++i){ 47 for(int s=0;s<(1<<n);++s){ 48 f[i][s]|=f[i-1][s]; 49 for(int j=1;j<=n;++j){ 50 f[i][s^dp[j][i]]|=f[i-1][s]; 51 } 52 } 53 } 54 for(int i=0;i<=n;++i){ 55 if(f[i][s]){ 56 ans=i; 57 break; 58 } 59 } 60 printf("%d\n",ans); 61 return 0; 62 }