施工中(8/13)
题目链接:http://codeforces.com/gym/101981
A.Adrien and Austin
队友写的,没看题
代码:
#include
using namespace std;
const int MAXN=1e6+5;
int n,k;
void solve()
{
int flag=1;
if(n==0)
flag=0;
if(k==1&&n%2==0)
flag=0;
if(flag)
{
printf("Adrien\n");
}
else
{
printf("Austin\n");
}
}
int main()
{
while(~scanf("%d%d",&n,&k))
{
solve();
}
return 0;
}
D.Country Meow
最小球覆盖板题
代码:
#include
const int MAXN=105;
const double eps=1e-8;
struct Tpoint
{
double x,y,z;
};
int npoint,nouter;
Tpoint pt[MAXN],outer[4],res;
double radius,tmp;
inline double dist(Tpoint p1,Tpoint p2)
{
double dx=p1.x-p2.x,dy=p1.y-p2.y,dz=p1.z-p2.z;
return (dx*dx+dy*dy+dz*dz);
}
inline double dot(Tpoint p1,Tpoint p2)
{
return p1.x*p2.x+p1.y*p2.y+p1.z*p2.z;
}
void ball()
{
Tpoint q[3];double m[3][3],sol[3],L[3],det;
res.x=res.y=res.z=radius=0;
switch(nouter)
{
case 1: res=outer[0];break;
case 2:
res.x=(outer[0].x+outer[1].x)/2;
res.y=(outer[0].y+outer[1].y)/2;
res.z=(outer[0].z+outer[1].z)/2;
radius=dist(res,outer[0]);
break;
case 3:
for(int i=0;i<2;i++)
{
q[i].x=outer[i+1].x-outer[0].x;
q[i].y=outer[i+1].y-outer[0].y;
q[i].z=outer[i+1].z-outer[0].z;
}
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
m[i][j]=dot(q[i],q[j])*2;
}
}
for(int i=0;i<2;i++)
{
sol[i]=dot(q[i],q[i]);
}
if(fabs(det=m[0][0]*m[1][1]-m[0][1]*m[1][0])eps)
{
outer[nouter]=pt[i];
++nouter;
minball(i);
--nouter;
}
if(i>0)
{
Tpoint Tt=pt[i];
memmove(&pt[1],&pt[0],sizeof(Tpoint)*i);
pt[0]=Tt;
}
}
}
}
double smallest_ball()
{
radius=-1;
for(int i=0;ieps)
{
nouter=1;
outer[0]=pt[i];
minball(i);
}
}
return sqrt(radius);
}
int main()
{
scanf("%d",&npoint);
for(int i=0;i
E.Eva and Euro coins
参考https://blog.csdn.net/sinat_32872703/article/details/84233142
代码:
#include
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair pii;
const int MAXN=1e6+5;
int n,k;
char s[MAXN],t[MAXN];
int st[MAXN],sz[MAXN];
string doit(char x[])
{
if(k==1) return "";
int len=0;
for(int i=1;i<=n;i++)
{
if(len&&st[len]==x[i])
{
sz[len]++;
if(sz[len]==k)
len--;
}
else
{
len++;
st[len]=x[i];
sz[len]=1;
}
}
string ret="";
for(int i=1;i<=len;i++)
{
for(int j=1;j<=sz[i];j++)
ret+=st[i];
}
return ret;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d%d",&n,&k);
scanf("%s",s+1);
scanf("%s",t+1);
string A=doit(s);
string B=doit(t);
if(A==B) puts("Yes");
else puts("No");
return 0;
}
G.Pyramid
找了个麻烦的规律。。。被我们卡过去了
代码:
#include
using namespace std;
const int MAXN=1e6+5;
const int MOD=1e9+7;
typedef long long ll;
struct node
{
int x,id;
bool operator < (const node &o)const
{
return x=0;i--)
{
if((o>>i)&1)
b=p[i]-b;
}
return b;
}
int ans[MAXN];
inline char nc()
{
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline void rea(int &x)
{
char c=nc();x=0;
for(;c>'9'||c<'0';c=nc());for(;c>='0'&&c<='9';x=x*10+c-'0',c=nc());
}
int main()
{
//freopen("in.txt","r",stdin);
int T;
//scanf("%d",&T);
rea(T);
for(int i=1;i<=T;i++)
{
//scanf("%d",&sv[i].x);
rea(sv[i].x);
sv[i].id=i;
}
Matrix b;
p[0].init();
for(int i=1;i<=30;i++)
{
p[i]=p[i-1]*p[i-1];
}
b.b[0][0]=15;b.b[1][0]=5;b.b[2][0]=1;b.b[3][0]=4;b.b[4][0]=1;
sort(sv+1,sv+1+T);
sv[0].x=3;
for(int i=1;i<=T;i++)
{
int id=sv[i].id;
if(sv[i].x==1) ans[id]=1;
else if(sv[i].x==2) ans[id]=5;
else if(sv[i].x==3) ans[id]=15;
else
{
if(sv[i-1].x<=3) sv[i-1].x=3;
int det=sv[i].x-sv[i-1].x;
b=qpow(b,det);
ans[id]=b.b[0][0];
}
}
for(int i=1;i<=T;i++)
printf("%d\n",(ans[i]+MOD)%MOD);
}
I.Magic Potion
网络流裸题
代码:
#include
using namespace std;
const int MAXN=505*2;
const int MAXM=1e6+5;
const int INF=0x3f3f3f3f;
typedef long long ll;
namespace DINIC
{
struct Edge
{
int u,v,cap,nxt;
Edge(){}
Edge(int _u,int _v,int _cap,int _nxt):u(_u),v(_v),cap(_cap),nxt(_nxt){}
}E[MAXM];
int head[MAXN],dis[MAXN],vis[MAXN];
int tol;
void init()
{
tol=0;
memset(head,-1,sizeof(head));
}
void addedge(int u,int v,int cap)
{
E[tol]=Edge(u,v,cap,head[u]);
head[u]=tol++;
E[tol]=Edge(v,u,0,head[v]);
head[v]=tol++;
}
bool BFS(int S,int T)
{
queue q;
q.push(S);
memset(dis,0x3f,sizeof(dis));
dis[S]=0;
while(!q.empty())
{
int x=q.front();
q.pop();
for(int i=head[x];~i;i=E[i].nxt)
{
if(E[i].cap>0&&dis[E[i].v]==INF)
{
dis[E[i].v]=dis[x]+1;
if(E[i].v==T)
return true;
q.push(E[i].v);
}
}
}
return dis[T]0)
{
int flow=dfs(E[i].v,min(maxflow,E[i].cap),T);
if(flow)
{
ret+=flow;
maxflow-=flow;
E[i].cap-=flow;
E[i^1].cap+=flow;
}
if(maxflow==0)
break;
}
}
return ret;
}
ll dinic(int S,int T,int N)
{
ll ans=0;
while(BFS(S,T))
{
int flow;
for(int i=0;i<=N;i++)
{
vis[i]=head[i];
}
while(flow=dfs(S,INF,T))
ans+=(ll)flow;
}
return ans;
}
}
using namespace DINIC;
int main()
{
int n,m,k;
init();
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++)
{
int num;
scanf("%d",&num);
for(int j=1;j<=num;j++)
{
int x;
scanf("%d",&x);
addedge(i,n+x,1);
}
}
for(int i=1;i<=n;i++)
{
addedge(0,i,1);
addedge(n+m+1,i,1);
}
for(int i=1;i<=m;i++)
{
addedge(n+i,n+m+2,1);
}
addedge(0,n+m+1,k);
ll ans=dinic(0,n+m+2,n+m+3);
printf("%lld\n",ans);
}
J.Prime Game
暴力
代码:
#include
#define pb push_back
using namespace std;
const int MAXN=1e6+5;
typedef long long ll;
int n;
vector pos[MAXN];
int mi[MAXN];
bool vis[MAXN];
void init()
{
for(int i=2;i
K.Kangaroo Puzzle
直接随机就能过
代码:
#include
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair pii;
string s="LRUD";
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
srand(time(0));
string ans="";
for(int i=1;i<=50000;i++)
{
int id=rand()%4;
ans+=s[id];
}
cout<
M.Mediocre String Problem
思路有点忘了...
好像是马拉车算回文半径之后乘另外一个串倒置后和当前点为后缀的公共前缀的长度
代码:
#include
#define pb push_back
typedef long long ll;
const int MAXN=1e6+5;
void pre_KMP(char x[],int m,int next[])
{
next[0]=m;
int j=0;
while(j+1i?std::min(Mp[2*id-i],mx-i):1;
while(i-Mp[i]>=0&&Ma[i+Mp[i]]==Ma[i-Mp[i]]) Mp[i]++;
if(i+Mp[i]>mx)
{
mx=i+Mp[i];
id=i;
}
}
for(int i=0;i0) dp[i-1]--;
}
for(int i=l-1;i>=0;i--)
{
dp[i]+=dp[i+1];
}
for(int i=0;i