爆炸才是最好的,反正我都是被大佬乜视的蒟蒻
(1)sushi
两种颜色的sushi围成一圈,求两者分为两块的最小互换次数
枚举分野点
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<iomanip>
#define int long long
using namespace std;
inline int read(){
int i=0,f=1;
char ch;
for(ch=getchar();!isdigit(ch);ch=getchar())
if(ch=='-') f=-1;
for(;isdigit(ch);ch=getchar())
i=(i<<3)+(i<<1)+(ch^48);
return i*f;
}
int buf[1024];
inline void write(int x){
if(!x){putchar('0');return ;}
if(x<0){putchar('-');x=-x;}
while(x) buf[++buf[0]]=x%10,x/=10;
while(buf[0]) putchar(buf[buf[0]--]+48);
return ;
}
#define stan 1111111
int T,sze[stan],cnt,len,ans1,ans2,lef,righ;
char s[stan];
signed main(){
T=read();
while(T--){
memset(sze,0,sizeof(sze));
cnt=0;
scanf("%s",s+1);
len=strlen(s+1);
for(int i=1;i<=len;++i){
if(s[i]!=s[i-1])
++cnt;
++sze[cnt];
}
ans1=ans2=0;
lef=0;righ=0;
for(int i=2;i<=cnt;i+=2)
righ+=sze[i];
for(int i=1;i<=cnt;i+=2){
lef+=sze[i-1];
righ-=sze[i-1];
ans1+=sze[i]*min(lef,righ);
}
lef=0;righ=0;
for(int i=1;i<=cnt;i+=2)
righ+=sze[i];
for(int i=2;i<=cnt;i+=2){
lef+=sze[i-1];
righ-=sze[i-1];
ans2+=sze[i]*min(lef,righ);
}
write(min(ans1,ans2));puts("");
}
return 0;
}
(2)pyramid
斜率优化裸题
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<iomanip>
#define int long long
using namespace std;
inline int read(){
int i=0,f=1;
char ch;
for(ch=getchar();!isdigit(ch);ch=getchar())
if(ch=='-') f=-1;
for(;isdigit(ch);ch=getchar())
i=(i<<3)+(i<<1)+(ch^48);
return i*f;
}
int buf[1024];
void write(int x){
if(!x){putchar('0');return ;}
if(x<0){putchar('-');x=-x;}
while(x){buf[++buf[0]]=x%10,x/=10;}
while(buf[0]) putchar(buf[buf[0]--]+48);
return ;
}
#define stan 22222
#define sten 111
int f[stan][2],num[stan],n,k,pos,l,r,que[stan],x,y,posi[sten];
inline double slope(int a,int b,int c){
return (double)(f[a][c]-f[b][c])*1.0/(a-b);
}
signed main(){
n=read();k=read();
for(int i=1;i<=n;++i){
x=read();y=read();
num[i]=y-x+1;
}
for(int j=1;j<=k;++j){
l=0,r=0,que[l]=0;
pos=j&1;
for(int i=1;i<=n;++i){
while(l<r&&slope(que[l],que[l+1],pos^1)>num[i]) ++l;
int t=que[l];
if(i==n) posi[j]=t;
f[i][pos]=f[t][pos^1]+num[i]*(i-t);
while(l<r&&slope(que[r],que[r-1],pos^1)<slope(i,que[r],pos^1)) --r;
que[++r]=i;
}
}
write(f[n][pos]);
return 0;
}
(3)heal
又名跳蚤…poj那道…
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<iomanip>
#define int unsigned long long
#define mod 1000000007
using namespace std;
inline int read(){
int i=0,f=1;
char ch;
for(ch=getchar();!isdigit(ch);ch=getchar())
if(ch=='-') f=-1;
for(;isdigit(ch);ch=getchar())
i=(i<<3)+(i<<1)+(ch^48);
return i*f;
}
int buf[1024];
inline void write(unsigned long long x){
if(!x){putchar('0');return ;}
if(x<0){putchar('-');x=-x;}
while(x){buf[++buf[0]]=x%10,x/=10;}
while(buf[0])putchar(buf[buf[0]--]+48);
return ;
}
#define stan 111111
unsigned long long n,m,a[stan],cnt,tot,b[stan],c[stan],cnt2;
unsigned long long rev,ans;
int gcd(int a,int b){
if(b) return gcd(b,a%b);
else return a;
}
unsigned long long ksm(unsigned long long a,unsigned long long b){
unsigned long long ret=1;
a%=mod;
while(b){
if(b&1) ret=(ret*a)%mod;
b>>=1;
a=(a*a)%mod;
}
return ret;
}
void split(int x){
for(int i=2;i*i<=x;++i)
if(x%i==0){
a[++cnt]=i;
while(x%i==0)
x/=i;
}
if(x>1) a[++cnt]=x;
return ;
}
void getsum(int pos,int lev,int en){
if(lev==en){
unsigned long long temp=m;
for(int i=0;i<lev;++i)
temp/=c[i];
rev=(rev+ksm(temp,n))%mod;
return ;
}
for(int i=pos;i<=cnt;++i){
c[lev]=a[i];
getsum(i+1,lev+1,en);
}
}
signed main(){
n=read();m=read();
split(m);
ans=ksm(m,n);
for(int i=1;i<=cnt;++i){
rev=0;
getsum(1,0,i);
if(i&1) ans=(ans-rev+mod)%mod;
else ans=(ans+rev)%mod;
}
write(ans);
return 0;
}