A - Daily Cookie
int n,k;cin>>n>>k;string p;cin>>p;int c=0;Rep(i,p.length()) c+=p[i]=='@';cout<<n-c+min(k,c);
B - Daily Cookie 2
int n,k;cin>>n>>k;string p;cin>>p;RepD(i,n-1) {if(p[i]=='@' && k) --k,p[i]='.';}cout<<p;
C - Kaiten Sushi
pair<int,int> a[(int)2e5+10];
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout);int n,m;cin>>n>>m;int l=0;For(i,n) {int p=read();if(l>0 && -a[l].fi<=p) continue;a[++l]={-p,i};}For(i,m) {int p=read();int id=upper_bound(a+1,a+1+l,mp(-p,0))-a;if(id>l) puts("-1");elsecout<<a[id].se<<endl;
// cout<<lower_bound(a+1,a+1+l,mp(p,0))-a<<endl;} return 0;
}
D - Keep Distance
int m,a[1010]={-9},n;
int x=0;
void dfs(int l) {if(l>n) {++x;return;}Fork(i,a[l-1]+10,m) {if(m-i>=10*(n-l)){a[l]=i;dfs(l+1);}else break;}
}
void dfs2(int l) {if(l>n) {PRi(a,n)return;}Fork(i,a[l-1]+10,m) {if(m-i>=10*(n-l)){a[l]=i;dfs2(l+1);}else break;}
}
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout);cin>>n>>m;dfs(1);cout<<x<<endl;dfs2(1);return 0;
}
E - Expansion Packs
int n,x;
double g[5010][5010]={},p[5010];
double f[5010];
int main()
{
// freopen("e.in","r",stdin);
// freopen(".out","w",stdout);cin>>n>>x;For(i,n) cin>>p[i];For(i,n) p[i]/=100.;g[0][0]=1;
// PRi(p,n)For(i,n) {Rep(j,i+1)g[i][j]=g[i-1][j]*(1-p[i])+g[i-1][j-1]*p[i];}
// Rep(j,n+1) cout<<g[n][j]<<endl;f[0]=0;For(i,x) {f[i]=1;For(j,n) if(i-j>0)f[i]+=f[i-j]*g[n][j];f[i]/=(1.-g[n][0]);}cout<<setprecision(10)<<f[x]<<endl;return 0;
}
G - Tile Distance 3
构造题
如图所示,已知K,对每个K*K的矩形横纵切K-1刀。按上面的样子拼。
2个矩形相邻当且仅当有有长度为正的公共边。
求任意2个点(保证不在格点上)所在的矩形间,至少经过几个相邻的矩形。
考虑通过旋转平移把其中一个点固定到(0,0)这个方块中。
平移和旋转,将其中一个点放到(i=0,j=0)的矩形中。
在通过翻转x=k/2,y=k/2把另一个点放到第一象限或xy正半轴。
然后分类讨论。
假设另一个点在y正半轴。
向右移动的过程中,直接移动, ( i , j , k ) − > ( i , j , k ′ ) (i,j,k)->(i,j,k') (i,j,k)−>(i,j,k′)只需要2步,可以优化。向上同理。
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \For(j,m-1) cout<<a[i][j]<<' ';\cout<<a[i][m]<<endl; \}
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{int x=0,f=1; char ch=getchar();while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}return x*f;
}
bool iseven(ll x) {return x%2==0;}
ll k,sx,sy,tx,ty;
tuple<int,ll,ll,ll> get(ll x,ll y) {ll px=(x>=0)?(x/k):((x+1)/k-1),py=(y>=0)?(y/k):((y+1)/k-1),j;int d=0; //0 - 1 |if(iseven(px)==iseven(py)) d=0,j=(y%k+k)%k;else d=1,j=(x%k+k)%k;return {d,px,py,j};
}
pair<ll,ll> rotate90(ll x,ll y) {return {y,-x-1};
}int main()
{
// freopen("g.in","r",stdin);
// freopen(".out","w",stdout);int T;k=3;cin>>T;while(T--) {cin>>k>>sx>>sy>>tx>>ty;auto [d1,i1,j1,k1]=get(sx,sy);if(d1) {tie(sx,sy)=rotate90(sx,sy);tie(tx,ty)=rotate90(tx,ty);}ll newsx=(sx%k+k)%k,newsy=(sy%k+k)%k;ll mvx=newsx-sx,mvy=newsy-sy;sx+=mvx;sy+=mvy;tx+=mvx;ty+=mvy;tie(d1,i1,j1,k1)=get(sx,sy);auto [d2,i2,j2,k2]=get(tx,ty);assert(d1==0 && i1==0 && j1==0);if(i2<0) { //flip x==k/2i2=-i2;if(d2%2==1) k2=k-1-k2;}if(j2<0) { //flip y==k/2j2=-j2;k1=k-1-k1;if(d2%2==0) k2=k-1-k2;}if(i2==0 && j2==0) {if(k1==k2) puts("0");else if(k1==k2+1 || k1==k2-1) puts("1");else puts("2");continue;} ll ans=0; ll dis=(i2==j2)?(i2-1) : (min(i2,j2));ans+=dis*2;i2-=dis,j2-=dis;if(i2==1 && j2==1) {ans+=min(k-1-k1+2,2+min(2ll,k2));cout<<ans<<endl;continue;}if(i2>0) {ans+=i2/2*(min(3ll,k)+1)+(i2%2)*(min(k2+1,3ll));cout<<ans<<endl;continue;}if(j2>0) {ll minO1O2=min(k-k1-1,2ll)+1;if(j2%2==1) cout<<ans+minO1O2+j2/2*min(4ll,k+1)<<endl;else {cout<<ans+minO1O2+min(3ll,k2+1)+(j2>=4)*(j2/2-1)*min(4ll,k+1)<<endl;}}}return 0;
}