c
思路分析
比赛时的思路,过于注重的关注了重复数字的情况,而没有关注到为什么重复数字不行的原因,所以一直wa
下面是我错误代码:
#include <bits/stdc++.h>
using namespace std;
long long s=0;
int a[100000+5],b[100000+5];
struct rule
{
bool operator()(const int &a1,const int &a2)const
{
return (a1|s)>(a2|s);
}
};
int main ()
{
int n;
cin>>n;
for(int i=0; i<n; i++)
cin>>a[i];
sort(a,a+n);
int c=0,t=-1,tc=0;
for(int i=0; i<n; i++)
cout<<a[i]<<" ";cout<<endl;
for(int i=0; i<n; i++)
{
if(t==-1)
{
t=a[i];
tc=1;
}
else
{
if(a[i]==t) tc++;
else
{
if(tc==1)
{
b[c++]=t;
}
else
{
s|=t;
tc=1;
}
}
t=a[i];
}
if(i==n-1&&tc==1)
b[c++]=t;
}
/**/cout<<s<<endl;
cout<<(s|b[0])<<" "<<(b[0]|s)<<endl;
for(int i=0; i<c; i++)
cout<<b[i]<<" ";cout<<endl;
if(c==0)
for(int i=n-1; i>=0; i++)
{
cout<<a[i];
if(i>0) cout<<" ";
}
else
{
sort(b,b+c,rule());
//for(int i=0; i<c; i++)
//cout<<b[i]<<" ";cout<<endl;
int t=b[0];
cout<<b[0];
for(int i=0; i<n; i++)
if(a[i]==t) continue;
else cout<<" "<<a[i];
}
return 0;
}
下面是我比赛之后补题的代码
#include <bits/stdc++.h>
using namespace std;
int a[100000+5],b[35][2];
int main ()
{
int n;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>a[i];
int t=a[i];
for(int j=0; j<35; j++)
{
if(t%2)
{
b[j][0]+=t%2;
b[j][1]=i;
}
t/=2;
}
}
int s=-1;
for(int i=34; i>=0; i--)
{
if(b[i][0]==1)
{
s=b[i][1];
break;
}
}
if(s!=-1)
{
cout<<a[s];
for(int i=0; i<n; i++)
if(i!=s) cout<<" "<<a[i];
}
else for(int i=0; i<n; i++)
{
cout<<a[i];
if(i<n-1) cout<<" ";
}
cout<<endl;
return 0;
}
相较于之前的代码好短。
E
题意不太理解(英语好弱呀/哭泣/)
理解成的圆内接正多边形
错误代码:
#include <bits/stdc++.h>
using namespace std;
int x[100000+5],y[100000+5];
long long gcd(long long a,long long b)
{
if(a%b==0) return abs(b);
return gcd(b,a%b);
}
int main ()
{
int n;
cin>>n;
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
long long sx=0,sy=0;
for(int i=0; i<n; i++)
{
cin>>x[i]>>y[i];
sx+=x[i],sy+=y[i];
}
for(int i=1; i<n; i++)
{//半径公式推导
long long t1=x[i]-x[0],t2=2*sx-n*(x[i]+x[0]);
long long t3=y[0]-y[i],t4=2*sy-n*(y[i]+y[0]);
if(t1!=0&&t2!=0&&t3!=0&&t4!=0)
{
long long t=gcd(t1,t3);
t1/=t,t3/=t;t=gcd(t1,t4);
t1/=t,t4/=t;t=gcd(t2,t3);
t2/=t,t3/=t;t=gcd(t2,t4);
t2/=t,t4/=t;
if((t1==t3&&t2==t4)||(t1==t4&&t2==t3)) continue;
else
{
cout<<"no"<<endl;
return 0;
}
}
else
{
if((t1==0||t2==0)&&(t3==0||t4==0)) continue;
else
{
cout<<"no";
return 0;
}
}
}
cout<<"YES"<<endl;
return 0;
}
理解题意之后的正确代码
#include <bits/stdc++.h>
using namespace std;
int x[100000+5],y[100000+5];
long long gcd(long long a,long long b)
{
if(a%b==0) return abs(b);
return gcd(b,a%b);
}
int main ()
{
int n;
cin>>n;
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
long long sx=0,sy=0,tx,ty;
int flag=n%2;
for(int i=0; i<n; i++)
{
cin>>x[i]>>y[i];
if(i>=n/2&&flag==0)
{
if(i==n/2)
{
tx=x[i]+x[0];
ty=y[i]+y[0];
}
else
{
if(tx==x[i]+x[i-n/2]&&ty==y[i]+y[i-n/2])continue;
else flag=1;
}
}
}
if(flag==1) cout<<"no";
else cout<<"YES"<<endl;
return 0;
}
总结:
这场div2看错了时间,少打了半小时(感觉多半小时也不会怎么样)再加油吧!
再次立个flag,每天更新博客。
第一次写文章,第一次补题,请大家多多支持。