This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2, 100]. Your task is to say if the hidden number is prime or composite.
Integer x > 1 is called prime if it has exactly two distinct divisors, 1 and x. If integer x > 1 is not prime, it’s called composite.
You can ask up to 20 queries about divisors of the hidden number. In each query you should print an integer from interval [2, 100]. The system will answer “yes” if your integer is a divisor of the hidden number. Otherwise, the answer will be “no”.
For example, if the hidden number is 14 then the system will answer “yes” only if you print 2, 7 or 14.
When you are done asking queries, print “prime” or “composite” and terminate your program.
You will get the Wrong Answer verdict if you ask more than 20 queries, or if you print an integer not from the range [2, 100]. Also, you will get the Wrong Answer verdict if the printed answer isn’t correct.
You will get the Idleness Limit Exceeded verdict if you don’t print anything (but you should) or if you forget about flushing the output (more info below).
第一次做交互题。
100以内有25个质数,所以考虑合数,100以内的一个数是合数当且仅当它为2,3,5,7的倍数。
#include
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 Rep(i,n) for(int i=0;i
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;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,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector
#define pi pair
#define SI(a) ((a).size())
typedef long long ll;
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+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
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;
}
#define MAXN (100+10)
int p[MAXN],tot;
bool b[MAXN]={0};
void make_prime(int n)
{
tot=0;
Fork(i,2,n)
{
if (!b[i]) p[++tot]=i;
For(j,tot)
{
if (i*p[j]>n) break;
b[i*p[j]]=1;
if (i%p[j]==0) {
break;
}
}
}
}
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout);
make_prime(100);
// For(i,tot) cout<
// cout<
bool flag=0;
For(i,4) {
cout<char
response[10];
scanf("%s", response);
if (strcmp(response, "no") == 0) continue;
bool flag=0;
For(j,tot) {
if (p[i]*p[j]>100) break;
printf("%d\n", p[i]*p[j]);
fflush(stdout);
char response[10];
scanf("%s", response);
if (strcmp(response, "no") == 0) continue;
else {
puts("composite");fflush(stdout); return 0;
}
}
puts("prime");fflush(stdout); return 0;
}
puts("prime"); fflush(stdout); return 0;
return 0;
}
Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length.
A block with side a has volume a3. A tower consisting of blocks with sides a1, a2, …, ak has the total volume a13 + a23 + … + ak3.
Limak is going to build a tower. First, he asks you to tell him a positive integer X — the required total volume of the tower. Then, Limak adds new blocks greedily, one by one. Each time he adds the biggest block such that the total volume doesn’t exceed X.
Limak asks you to choose X not greater than m. Also, he wants to maximize the number of blocks in the tower at the end (however, he still behaves greedily). Secondarily, he wants to maximize X.
Can you help Limak? Find the maximum number of blocks his tower can have and the maximum X ≤ m that results this number of blocks.
1 ≤ m ≤ 10^15
对于1个X,要么取最大的v[x],要么取次大的v[x-1],再小的一定不优
官方证明http://codeforces.com/blog/entry/45310
给一个n*n的矩阵,有一些地方是障碍,你可以移除一个k*k的子矩阵的所有障碍,问之后的最大连通块大小。
n<=500
枚举k*k的子矩阵位置,每次向一个方向移一格,暴力处理相邻4k个方格的连通块,
复杂度 O(nk(k+n))
#include
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 Rep(i,n) for(int i=0;i
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;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,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector
#define pi pair
#define SI(a) ((a).size())
typedef long long ll;
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+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
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;
}
#define MAXN (510)
int n,k;
int a[MAXN][MAXN],c_sz[MAXN*MAXN]={0},c[MAXN][MAXN]={0};
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int mark[MAXN*MAXN]={0};
bool inside(int x,int y) {
return 0void dfs(int x,int y,int col) {
c[x][y]=col;
c_sz[col]++;
Rep(di,4) {
int nx=x+dir[di][0],ny=y+dir[di][1];
if (inside(nx,ny)&&a[nx][ny]&&!c[nx][ny]) dfs(nx,ny,col);
}
}
void modi(int x,int y,int t,int &ans) {
int id=c[x][y];
// cout<
if (!inside(x,y)||!a[x][y]) return;
if (mark[id]!=t) {
mark[id]=t;
ans+=c_sz[id];
}
}
int main()
{
// freopen("C.in","r",stdin);
// freopen(".out","w",stdout);
cin>>n>>k;
For(i,n) {
char s[MAXN];
cin>>(s+1);
For(j,n) a[i][j]=(s[j]=='.');
}
int tot=0;
For(i,n) For(j,n) if (a[i][j]&&c[i][j]==0) {
dfs(i,j,++tot);
}
int bestans=0,cur_time=1;
For(i,n-k+1) {
Fork(x,i,i+k-1)
For(y,k) {
if (c[x][y]) --c_sz[c[x][y]];
}
For(j,n-k+1) {
int ans=0;
For(l,k) {
modi(i-1,j+l-1,cur_time,ans);
modi(i+k,j+l-1,cur_time,ans);
modi(i+l-1,j-1,cur_time,ans);
modi(i+l-1,j+k,cur_time,ans);
}
bestans=max(bestans,ans);
++cur_time;
if (j1 )
For(l,k) {
if (c[i+l-1][j]) ++c_sz[c[i+l-1][j]];
if (c[i+l-1][j+k]) --c_sz[c[i+l-1][j+k]];
}
}
Fork(x,i,i+k-1)
Fork(y,n-k+1,n) {
if (c[x][y]) ++c_sz[c[x][y]];
}
}
cout<return 0;
}
算清楚概率 O(n3) 暴力
假设从g1出发到距离为d的点,明天要考虑的只有距离为d-1,d,d+1的,
对每个g1来说1个点最多考虑3次
其实还是要算清楚概率
PS:Tutorial http://codeforces.com/blog/entry/45310
官解写的略诡异看不出来,后来自己写了一遍发现式子一样。。。
#include
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 Rep(i,n) for(int i=0;i
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;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,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector
#define pi pair
#define SI(a) ((a).size())
typedef long long ll;
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+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
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;
}
#define MAXN (410)
vi edges[MAXN];
int n,m,f[MAXN][MAXN];
double pro[MAXN],pro_dis[MAXN];
bool b[MAXN];
double calc(int g1,int d1,int cnt) {
MEM(pro) MEM(b) MEM(pro_dis)
vi visit_point;
For(i,n) if (f[g1][i]==d1) {
int sz=SI(edges[i]);
Rep(j,sz) {
int v=edges[i][j];
pro[v]+=1./cnt/sz;
if (!b[v]) b[v]=1,visit_point.pb(v);
}
}
// which city use BGDS tomorrow
double ans=0;
For(i,n) {
int sz=SI(visit_point);
Rep(j,sz) {
int v=visit_point[j];
pro_dis[f[i][v]] =max(pro_dis[f[i][v]],pro[v]);
}
double an=0;
Rep(j,sz) {
int v=visit_point[j];
an+=pro_dis[f[i][v]];
pro_dis[f[i][v]]=0;
}
ans=max(ans,an);
}
return ans;
}
int main()
{
// freopen("D.in","r",stdin);
// freopen(".out","w",stdout);
cin>>n>>m;
MEMI(f)
For(i,n) f[i][i]=0;
For(i,m) {
int a=read(),b=read();
f[a][b]=f[b][a]=min(f[a][b],1);
edges[a].pb(b);
edges[b].pb(a);
}
For(k,n) For(i,n) For(j,n) if (f[i][k]!=INF&&f[k][j]!=INF)
f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
double ans=0;
For(i,n) {
double nowans=0;
Rep(d,n+1) {
int cnt=0;
For(j,n) if (f[i][j]==d) ++cnt;
if (!cnt) continue;
double p=(double)cnt/n;
// wait tomorrow
double t=calc(i,d,cnt);
nowans+=p*max(t,1./cnt);
}
ans=max(ans,nowans);
}
printf("%.12lf\n",ans);
return 0;
}