http://codeforces.com/gym/101309/attachments
过了6题,I题是紫书上原题都没有写出来,队友写炸了,比赛结束5分钟后改出来了(疯狂甩锅)
感觉NEERC的题目都不错,感觉都是可写的题
A:
solved by sdn
/*
ID: oodt
PROG:
LANG:C++
*/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<cassert>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<sstream>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int maxx=1005;
const int INF = 0x3f3f3f3f;
int n,m,k;
string a[maxx][maxx];
int q[maxx];
int vis[maxx];
int ans = 0,cnt = 0,pos = 0;
int l = 0,r = 0;
string s[maxx];
int main()
{
#ifdef LOCAL
freopen("/Users/ecooodt/Desktop/c++ and acm/_集训2/sp_13/a.txt","r",stdin);
#endif
freopen("alignment.in","r",stdin);
freopen("alignment.out","w",stdout);
while(getline(cin,s[cnt++])){}
int ma = 0;
rep(i,0,cnt){
stringstream ss(s[i]);
int j = 0;
while(ss>>a[i][j]){
ma = max(ma,j);
j++;
q[i] = j;
}
}
rep(j,0,ma)
{
rep(i,0,cnt){
vis[j] = max(SZ(a[i][j]),vis[j]);
}
}
rep(i,0,cnt){
rep(j,0,q[i]){
cout<<a[i][j];
if(j != q[i]-1)
rep(k,0,vis[j]-SZ(a[i][j])+1) cout<<" ";
}
cout<<endl;
}
return 0;
}
G:交互题,对称取即可
solved by lyy
/*
ID: oodt
PROG:
LANG:C++
*/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<cassert>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<sstream>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int maxx=1005;
const int INF = 0x3f3f3f3f;
int n,m,k;
string a[maxx][maxx];
int q[maxx];
int vis[maxx];
int ans = 0,cnt = 0,pos = 0;
int l = 0,r = 0;
string s[maxx];
int main()
{
#ifdef LOCAL
freopen("/Users/ecooodt/Desktop/c++ and acm/_集训2/sp_13/a.txt","r",stdin);
#endif
freopen("alignment.in","r",stdin);
freopen("alignment.out","w",stdout);
while(getline(cin,s[cnt++])){}
int ma = 0;
rep(i,0,cnt){
stringstream ss(s[i]);
int j = 0;
while(ss>>a[i][j]){
ma = max(ma,j);
j++;
q[i] = j;
}
}
rep(j,0,ma)
{
rep(i,0,cnt){
vis[j] = max(SZ(a[i][j]),vis[j]);
}
}
rep(i,0,cnt){
rep(j,0,q[i]){
cout<<a[i][j];
if(j != q[i]-1)
rep(k,0,vis[j]-SZ(a[i][j])+1) cout<<" ";
}
cout<<endl;
}
return 0;
}
K:
solved by wyq
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct Edge
{
int to,next;
}edge[2000005];
int head[10005],tot;
int max1=0;
int color[10005];
int used[100005];
void init()
{
tot=0;
memset(head,-1,sizeof(head));
memset(color,-1,sizeof(color));
}
void addedge(int u,int v)
{
edge[tot].to=v;
edge[tot].next=head[u];
head[u]=tot++;
}
void bfs(int now)
{
int i,v;
for(i=head[now];i!=-1;i=edge[i].next)
{
v=edge[i].to;
if(color[v]==-1)continue;
used[color[v]]=1;
}
for(i=1;i<=max1;i++)
{
if(used[i]==0)
{
color[now]=i;
break;
}
}
for(i=head[now];i!=-1;i=edge[i].next)
{
v=edge[i].to;
if(color[v]==-1)continue;
used[color[v]]=0;
}
for(i=head[now];i!=-1;i=edge[i].next)
{
v=edge[i].to;
if(color[v]!=-1)continue;
bfs(v);
}
}
int deg[10005];
int main()
{
freopen("kgraph.in","r",stdin);
freopen("kgraph.out","w",stdout);
init();
int n,m,i,x,y;
scanf("%d%d",&n,&m);
for(i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
addedge(x,y);
addedge(y,x);
deg[x]++;
deg[y]++;
}
for(i=1;i<=n;i++)
{
if(deg[i]>max1)max1=deg[i];
}
if(max1%2==0)max1++;
printf("%d\n",max1);
bfs(1);
for(i=1;i<=n;i++)
printf("%d\n",color[i]);
return 0;
}
E:简单dp
solved by lyy
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n,m;
struct st
{
int id;
int data;
};
ll dp[4005][4005];
int w[4005][4005];
st a[4005];
st b[4005];
int ans[4005];
bool cmp(st a,st b)
{
return a.data<b.data;
}
void dfs(int n,int m)
{
ans[a[n].id]=b[m].id;
if (n==1) return;
dfs(n-1,w[n][m]);
}
int main()
{
freopen("evacuation.in","r",stdin);
freopen("evacuation.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%d",&a[i].data);
a[i].id=i;
}
scanf("%d",&m);
for (int i=1;i<=m;i++)
{
scanf("%d",&b[i].data);
b[i].id=i;
}
sort(a+1,a+n+1,cmp);
sort(b+1,b+m+1,cmp);
for (int i=0;i<=n;i++)
{
for (int j=0;j<=m;j++)
{
dp[i][j]=1LL<<60;
}
}
dp[1][1]=abs(a[1].data-b[1].data);
for (int i=2;i<=n;i++)
{
for (int j=1;j<=min(i,m);j++)
{
dp[i][j]=min(dp[i-1][j-1],dp[i-1][j])+abs(a[i].data-b[j].data);
if (dp[i-1][j-1]>=dp[i-1][j]) w[i][j]=j;
else w[i][j]=j-1;
}
}
dfs(n,m);
printf("%I64d\n",dp[n][m]);
for (int i=1;i<=n;i++)
{
printf("%d",ans[i]);
if (i!=n) printf(" ");
}
printf("\n");
return 0;
}
D:用凸包乱搞,不过感觉是不是我想复杂了
solved by lyy ans wyq
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define eps 1e-8
int sgn(double x)
{
if(fabs(x)<eps)return 0;
if(x<0)return -1;
else return 1;
}
struct Point
{
double x,y;
Point(){}
Point(double _x,double _y)
{
x=_x;
y=_y;
}
Point operator -(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
double operator ^(const Point &b)const
{
return x*b.y-y*b.x;
}
double operator *(const Point &b)const
{
return x*b.x+y*b.y;
}
}point[10005];
struct line
{
Point a,b;
};
double xmult(Point p1,Point p2,Point p0)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
int same_side(Point p1,Point p2,line l)
{
return xmult(l.a,p1,l.b)*xmult(l.a,p2,l.b)>eps;
}
const int MAXN=10005;
int Stack[MAXN],top;
double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
}
bool _cmp(Point p1,Point p2)
{
double tmp=(p1-point[0])^(p2-point[0]);
if(sgn(tmp)>0)return true;
else if(sgn(tmp)==0 && sgn(dist(p1,point[0])-dist(p2,point[0]))<=0)
return true;
else return false;
}
void Graham(int n)
{
Point p0;
int k=0;
p0=point[0];
for(int i=1;i<n;i++)
{
if((p0.y>point[i].y)||(p0.y==point[i].y && p0.x>point[i].x))
{
p0=point[i];
k=i;
}
}
swap(point[k],point[0]);
sort(point+1,point+n,_cmp);
Stack[0]=0;
Stack[1]=1;
top=2;
for(int i=2;i<n;i++)
{
while(top>1 && sgn((point[Stack[top-1]]-point[Stack[top-2]])^(point[i]-point[Stack[top-2]]))<=0)
{
top--;
}
Stack[top++]=i;
}
}
int main()
{
freopen("dome.in","r",stdin);
freopen("dome.out","w",stdout);
int n,i,j;
double x,y,z;
bool p;
double xmax=0;
double ymax=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%lf%lf%lf",&x,&y,&z);
point[i].x=sqrt(x*x+y*y);
point[i].y=z;
if(point[i].x>xmax)xmax=point[i].x;
if(point[i].y>ymax)ymax=point[i].y;
}
point[n+1].x=xmax;
point[n+1].y=0;
point[n+2].x=0;
point[n+2].y=ymax;
point[0].x=0;
point[0].y=0;
Point point0;
point0.x=0;
point0.y=0;
n=n+3;
Graham(n);
double minsqu,minh,minr,nowh,nowr;
minsqu=1e30;
for(i=0;i<top;i++)
{
int next=(i+1)%top;
if(point[Stack[i]].x==point[Stack[next]].x || point[Stack[i]].y==point[Stack[next]].y)continue;
nowr=-point[Stack[i]].y*(point[Stack[i]].x-point[Stack[next]].x)/(point[Stack[i]].y-point[Stack[next]].y)+point[Stack[i]].x;
nowh=(point[Stack[i]].y-point[Stack[next]].y)/(point[Stack[i]].x-point[Stack[next]].x)*(-point[Stack[i]].x)+point[Stack[i]].y;
if(nowr*nowr*nowh<minsqu)
{
minsqu=nowr*nowr*nowh;
minh=nowh;
minr=nowr;
}
}
for(i=0;i<top;i++)
{
if(point[Stack[i]].x==0 || point[Stack[i]].y==0)continue;
p=true;
line l;
l.a=point[Stack[i]];
l.b.x=1.5*point[Stack[i]].x;
l.b.y=0;
for(j=0;j<top;j++)
{
if(i==j)continue;
if(!same_side(point0,point[Stack[j]],l))p=false;
}
nowh=3.0*point[Stack[i]].y;
nowr=1.5*point[Stack[i]].x;
if(nowr*nowr*nowh<minsqu && p)
{
minsqu=nowr*nowr*nowh;
minh=nowh;
minr=nowr;
}
}
printf("%.3lf %.3lf\n",minh,minr);
return 0;
}
F:数学题,并不算太难,筛一筛素因子即可
solved by lyy
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 10007
int n,m;
int a[10010];
int pri[maxn+5];
vector<int> v[10010];
int p[1500];
int s[10010][1300];
vector<pair<int,int> >ans;
void getPrime()
{
int i,j;
for (i=2;i<=maxn;i++)
{
if (pri[i]==0) pri[++pri[0]]=i;
for (j=1;j<=pri[0] && pri[j]<=maxn/i;j++)
{
pri[pri[j]*i]=1;
if (i%pri[j]==0) break;
}
}
}
vector<int> go(int x)
{
int o=x;
vector<int> ans;
for (int i=1;i<=pri[i];i++)
{
if (x%pri[i]==0)
{
while (x%pri[i]==0)
{
s[o][i]++;
ans.push_back(i);
x/=pri[i];
}
}
}
return ans;
}
bool can(int x)
{
for (int i=1;i<=pri[0];i++)
{
if (p[i]<s[x][i]) return false;
}
return true;
}
int find()
{
int l=2,r=10007;
int m;
while (l<=r)
{
m=(l+r)/2;
if (can(m)) l=m+1;
else r=m-1;
}
return r;
}
int main()
{
freopen("factorial.in","r",stdin);
freopen("factorial.out","w",stdout);
getPrime();
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
for (int j=1;j<=x;j++)
{
a[j]++;
}
}
for (int i=1;i<=m;i++)
{
int x;
scanf("%d",&x);
for (int j=1;j<=x;j++)
{
a[j]--;
}
}
for (int i=2;i<=10007;i++)
{
v[i]=go(i);
}
for (int i=2;i<=10000;i++)
{
for (auto x:v[i])
{
p[x]+=a[i];
}
}
for (int i=1;i<=pri[i];i++)
{
if (p[i]<0)
{
printf("-1\n");
return 0;
}
}
for (int i=3;i<=10007;i++)
{
for (int j=1;j<=pri[0];j++)
{
s[i][j]=s[i-1][j]+s[i][j];
}
}
if (find()==1)
{
printf("0\n");
}
else
{
int c;
while ((c=find())!=1)
{
int x=100000;
for (int i=1;i<=pri[0];i++)
{
if (s[c][i]>0) x=min(x,p[i]/s[c][i]);
}
ans.push_back({c,x});
for (int i=1;i<=pri[0];i++)
{
p[i]-=s[c][i]*x;
}
}
printf("%d\n",ans.size());
for (auto x:ans)
{
printf("%d %d\n",x.first,x.second);
}
}
return 0;
}