18.9.30
期望 80 实际 80
这个题应该是一个裸的容斥原理,但是我并不会写容斥原理,所以水了80
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
/*应该是容斥原理之类的, 但我并不会写容斥原理,只能手写n=2的情况*/ #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int m; long long n,a[21],b[21]; long long gcd(long long x,long long y){ return x==0?y:gcd(y%x,x); } int main(){ freopen("count.in","r",stdin); freopen("count.out","w",stdout); scanf("%I64d%d",&n,&m); for(int i=1;i<=m;i++) scanf("%I64d",&a[i]); if(n<=1000000){ long long ans=0; for(int i=1;i<=n;i++){ int flag=0; for(int j=1;j<=m;j++) if(i%a[j]==0) flag=1; if(flag==0) ans++; } cout<<ans; } else if(m==2){ long long ans=0; ans+=n/a[1];ans+=n/a[2]; ans-=n/(a[1]*a[2]/gcd(a[1],a[2])); cout<<n-ans; } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pr; const double pi=acos(-1); #define rep(i,a,n) for(int i=a;i<=n;i++) #define per(i,n,a) for(int i=n;i>=a;i--) #define Rep(i,u) for(int i=head[u];i;i=Next[i]) #define clr(a) memset(a,0,sizeof a) #define pb push_back #define mp make_pair #define putk() putchar(' ') ld eps=1e-9; ll pp=1000000007; ll mo(ll a,ll pp){if(a>=0 && a<pp)return a;a%=pp;if(a<0)a+=pp;return a;} ll powmod(ll a,ll b,ll pp){ll ans=1;for(;b;b>>=1,a=mo(a*a,pp))if(b&1)ans=mo(ans*a,pp);return ans;} ll gcd(ll a,ll b){return (!b)?a:gcd(b,a%b);} ll read(){ ll ans=0; char last=' ',ch=getchar(); while(ch<'0' || ch>'9')last=ch,ch=getchar(); while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar(); if(last=='-')ans=-ans; return ans; } void put(ll a){ if(a<0)putchar('-'),a=-a; int top=0,q[20]; while(a)q[++top]=a%10,a/=10; top=max(top,1); while(top--)putchar('0'+q[top+1]); } //head ll ans=0; int n,m,a[25]; ll Gcd(ll a,ll b){ if(!b)return a; return gcd(b,a%b); } void dfs(int dep,ll t,int flag){ if(t>n)return; if(dep==m+1){ ans+=n/t*flag; return; } dfs(dep+1,t,flag); dfs(dep+1,t/Gcd(t,a[dep])*a[dep],-flag); } int main(){ freopen("count.in","r",stdin); freopen("count.out","w",stdout); n=read(); m=read(); rep(i,1,m) a[i]=read(); dfs(1,1,1); cout<<ans<<endl; return 0; }
期望 60 实际 30
题目和题解说好的不一样,明明按照题解,sort是可以过60%的,但是挂了。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<cmath> #include<queue> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int n,k,tot; long long a[400001]; long long Max[400001][21],Min[400001][21]; priority_queue<long long>que; long long Querymax(int l,int r){ int k=log2(r-l+1); return max(Max[l][k],Max[r-(1<<k)+1][k]); } long long Querymin(int l,int r){ int k=log2(r-l+1); return min(Min[l][k],Min[r-(1<<k)+1][k]); } int main(){ freopen("kth.in","r",stdin); freopen("kth.out","w",stdout); scanf("%d%d",&n,&k); for(int i=1;i<=n;i++){ scanf("%I64d",&a[i]); Max[i][0]=Min[i][0]=a[i]; } for(int j=1;j<=21;j++) for(int i=1;i+(1<<j)-1<=n;i++) Max[i][j]=max(Max[i][j-1],Max[i+(1<<(j-1))][j-1]); for(int j=1;j<=21;j++) for(int i=1;i+(1<<j)-1<=n;i++) Min[i][j]=min(Min[i][j-1],Min[i+(1<<(j-1))][j-1]); for(int i=1;i<=n;i++) for(int j=i;j<=n;j++) que.push(Querymax(i,j)-Querymin(i,j)); while(!que.empty()){ long long now=que.top(); que.pop();tot++; if(tot==k){ cout<<now<<endl; return 0; } } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define N 410000 using namespace std; int a[N],q1[N],q2[N]; long long k; int n; bool check(int kk){ int l1=1,r1=1,l2=1,r2=1; q1[1]=1;q2[1]=1; int z=1; long long ans=0; if(kk==1) ans=1; else ans=0; for(int i=2;i<=n;i++){ while(l1<=r1&&a[q1[r1]]>=a[i]) --r1; q1[++r1]=i; while(l2<=r2&&a[q2[r2]]<=a[i]) --r2; q2[++r2]=i; while(z<i){ int t1=l1,t2=l2; ++z; while(q1[t1]<z) ++t1; while(q2[t2]<z) ++t2; if(a[q2[t2]]-a[q1[t1]]>=kk){ l1=t1; l2=t2; } else { --z; break; } } if(a[q2[l2]]-a[q1[l1]]>=kk) ans+=z; } return ans>=k; } int main(){ // freopen("kth.in","r",stdin); freopen("kth.out","w",stdout); scanf("%d%I64d",&n,&k); for(int i=1;i<=n;i++) scanf("%d",&a[i]); int l=0,r=1000000000; while(l<r){ int mid=(l+r+1)/2; if(check(mid)) l=mid; else r=mid-1; } cout<<l<<endl; return 0; }
期望10~30 实际 10
题解是这么说的,感觉很神奇。只用DP,甚至不用状压就可以写出来。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<ctime> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pr; const double pi=acos(-1); #define rep(i,a,n) for(int i=a;i<=n;i++) #define per(i,n,a) for(int i=n;i>=a;i--) #define Rep(i,u) for(int i=head[u];i;i=Next[i]) #define clr(a) memset(a,0,sizeof a) #define pb push_back #define mp make_pair #define INF 1000000000 ld eps=1e-9; ll pp=1000000007; ll mo(ll a,ll pp){if(a>=0 && a<pp)return a;a%=pp;if(a<0)a+=pp;return a;} ll powmod(ll a,ll b,ll pp){ll ans=1;for(;b;b>>=1,a=mo(a*a,pp))if(b&1)ans=mo(ans*a,pp);return ans;} ll read(){ ll ans=0; char last=' ',ch=getchar(); while(ch<'0' || ch>'9')last=ch,ch=getchar(); while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar(); if(last=='-')ans=-ans; return ans; } void put(ll n){ int top=0;int qq[22]; while(n)qq[++top]=n%10,n/=10; if(top==0)top=1,qq[0]=0; while(top)putchar('0'+qq[top]),top--; } //head #define N 5100 int dp[N/2][N],n,r; struct node{ int x,y; }q[N]; bool cmp(node a,node b){ return a.x<b.x; } void solved(){ n=read();r=read(); rep(i,1,n)q[i].x=read(); rep(i,1,n)q[i].y=read(); sort(q+1,q+n+1,cmp); int m=n/(1+r)+((n%(1+r))>0); int ans=0; rep(i,1,m){ int tt=min((1+r)*i,n); rep(j,0,tt-1)dp[i][j]=-INF; rep(j,tt,n)dp[i][j]=q[j].y+dp[i-1][j-1]; rep(j,1,n)dp[i][j]=max(dp[i][j],dp[i][j-1]); ans=max(ans,dp[i][n]); } printf("%d\n",ans); } int main(){ freopen("submax.in","r",stdin); freopen("submax.out","w",stdout); int T=read(); while(T--)solved(); return 0; }
这次考试很不理想,该拿的暴力分没有拿到,正解能想出来,但不会写,各种gg,zs。
吐槽出题人的头文件太恶心了。
细雨斜风作晓寒。淡烟疏柳媚晴滩。入淮清洛渐漫漫。
雪沫乳花浮午盏,蓼茸蒿笋试春盘。人间有味是清欢。