目录
Codeforces 1003
这么做是不是不太好啊233
A.Polycarp's Pockets
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
const int N=500;
int n,A[N],tm[N];
inline int read()
{
int now=0,f=1;register char c=gc();
for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now*f;
}
int main()
{
n=read();
for(int i=1; i<=n; ++i) ++tm[read()];
int res=0;
for(int i=1; i<=100; ++i) res=std::max(res,tm[i]);
printf("%d",res);
return 0;
}
B.Binary String Constructing
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
const int N=10000;
int A,B,X;
char s[N];
inline int read()
{
int now=0,f=1;register char c=gc();
for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now*f;
}
int main()
{
A=read(),B=read(),X=read();//A:0 B:1
int n=A+B;
// if(X==1)
// {
// for(int i=1; i<=A; ++i) putchar('0');
// for(int i=A+1; i<=n; ++i) putchar('1');
// return 0;
// }
const char f=A>=B?'1':'0', s=A>=B?'0':'1';
if(A>B) std::swap(A,B);
for(int i=1; i<=X; ++i)
putchar((i&1)?s:f), --((i&1)?B:A);
if(X&1)
{
for(int i=X+1; i<=X+B; ++i) putchar(s);
for(int i=X+B+1; i<=n; ++i) putchar(f);
}
else
{
for(int i=X+1; i<=X+A; ++i) putchar(f);
for(int i=X+A+1; i<=n; ++i) putchar(s);
}
return 0;
}
C.Intense Heat
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
#define eps (1e-8)
const int N=5007;
int n,K,A[N];
inline int read()
{
int now=0,f=1;register char c=gc();
for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now*f;
}
int main()
{
n=read(),K=read();
for(int i=1; i<=n; ++i) A[i]=read();
double ans=0;
for(int i=1; i<=n; ++i)//O(n^2) 这种暴力我最会写了233
{
int sum=0;
for(int j=i; j<=n; ++j)
{
sum+=A[j];
if(j-i+1>=K) ans=std::max(ans,1.0*sum/(j-i+1));
}
}
printf("%.10lf",ans);
return 0;
}
D.Coins and Queries
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#define gc() getchar()
const int N=2e5+5, INF=0x7fffffff;
int n,Q,A[N],tot[999],num[999];
inline int read()
{
int now=0;register char c=gc();
for(;!isdigit(c);c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now;
}
inline int Count(int x){
for(int i=0; i<31; ++i) if(x&(1<<i)) return i;
}
int Query()
{//写的好像麻烦了 当时非常zz
memcpy(num,tot,sizeof tot);
int B=read(),ans=0;
for(int i=30; ~i; --i)
{
if(!(B&(1<<i))) continue;
if(num[i]) ++ans;
else
{
int need=1<<i;
for(int j=i-1; ~j&&need; --j)
{
if(!num[j]) continue;
int v=std::min(num[j],need>>j);//need/(1<<j);//not ceil!
ans+=v, need-=v*(1<<j), num[j]-=v;
}
if(need) return -1;
}
}
return ans;
}
int main()
{
n=read(), Q=read();
for(int i=1; i<=n; ++i) ++tot[Count(read())];
while(Q--) printf("%d
",Query());
return 0;
}
比赛结束后
E.Tree Constructing(贪心)
贪心策略显然 但可能要注意特殊情况(比如D=N-1,K=1)。
WA了四次结果结束后发现脑抽写错一行 改了就A了啊mmp
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
const int N=4e5+7,M=N<<1;
int n,D,K,now,dgr[N],Enum,H[N],nxt[M],to[M];
inline int read()
{
int now=0;register char c=gc();
for(;!isdigit(c);c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now;
}
inline void AddEdge(int u,int v)
{
++dgr[u], to[++Enum]=v, nxt[Enum]=H[u], H[u]=Enum;
++dgr[v], to[++Enum]=u, nxt[Enum]=H[v], H[v]=Enum;
}
void Link(int x,int dep)
{
if(!dep) return;
for(int i=K-dgr[x]; i>0&&now<n; --i) AddEdge(x,++now), Link(now,dep-1);
}
bool Solve()
{
if(D>=n) return 0;
for(int i=1; i<=D; ++i) AddEdge(i,i+1);
now=D+1;
for(int i=2; i<=D&&now<n; ++i) Link(i,D-std::max(i-1,D+1-i));
for(int i=1; i<=n; ++i) if(dgr[i]>K) return 0;
// DFS1(1,1,0), Max=0, DFS1(V,V,0);
// if(Max!=D) return 0;
return now>=n;
}
void DFS_for_Ans(int x,int f)
{
for(int i=H[x]; i; i=nxt[i])
if(to[i]!=f) printf("%d %d
",x,to[i]), DFS_for_Ans(to[i],x);
}
int main()
{
n=read(), D=read(), K=read();
if(Solve()) puts("YES"), DFS_for_Ans(1,1);
else puts("NO");
return 0;
}
F.Abbreviation
待补