[NWPU2018]国庆训练赛第七场 2018-10-07

B - The E-pang Palace
这个题是队友写的,但WA了。检查了一下她的代码,她没有考虑完全包含的情况
因为点的个数很少,直接暴力枚举。先记录下所有矩形,然后挨个检查是否符合情况。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>

using namespace std;

int n,cor[100][2],cnt;

struct node
{
	long long area;
	int weizhi[5][2];
}juxing[500000];

int main()
{
	scanf("%d",&n);
	while(n)
	{
		cnt=0;
		memset(juxing,0,sizeof(0));
		memset(cor,0,sizeof(0));
		for(int i=1;i<=n;i++)scanf("%d%d",&cor[i][0],&cor[i][1]);
		if(n<8)
		{
			    printf("imp\n");
		    	scanf("%d",&n);
		    	continue;
		}
		for(int i=1;i<=n;i++)
			for(int j=i+1;j<=n;j++)
		        for(int k=j+1;k<=n;k++)
		            for(int g=k+1;g<=n;g++)
		            {
			                 if(cor[i][0]==cor[j][0])
			                 {
			                 	if((cor[i][1]==cor[k][1])&&(cor[g][1]==cor[j][1])&&(cor[g][0]==cor[k][0]))
			                 	{
			                 		cnt++;
			                 		juxing[cnt].area=(cor[i][1]-cor[j][1])*(cor[i][0]-cor[k][0]);
			                 		juxing[cnt].weizhi[1][1]=cor[i][1];juxing[cnt].weizhi[1][0]=cor[i][0];
			                 		juxing[cnt].weizhi[2][1]=cor[k][1];juxing[cnt].weizhi[2][0]=cor[k][0];
			                 		juxing[cnt].weizhi[3][1]=cor[j][1];juxing[cnt].weizhi[3][0]=cor[j][0];
			                 		juxing[cnt].weizhi[4][1]=cor[g][1];juxing[cnt].weizhi[4][0]=cor[g][0];
			                 	}
			                 	if((cor[i][1]==cor[g][1])&&(cor[k][0]==cor[g][0])&&(cor[k][1]==cor[j][1]))
			                 	{
			                 		cnt++;
			                 		juxing[cnt].area=(cor[i][1]-cor[j][1])*(cor[i][0]-cor[g][0]);
			                 		juxing[cnt].weizhi[1][1]=cor[i][1];juxing[cnt].weizhi[1][0]=cor[i][0];
			                 		juxing[cnt].weizhi[2][1]=cor[g][1];juxing[cnt].weizhi[2][0]=cor[g][0];
			                 		juxing[cnt].weizhi[3][1]=cor[j][1];juxing[cnt].weizhi[3][0]=cor[j][0];
			                 		juxing[cnt].weizhi[4][1]=cor[k][1];juxing[cnt].weizhi[4][0]=cor[k][0];
			                 	}
			                 }
			                 if(cor[i][0]==cor[k][0])
			                 {
			                 	if((cor[i][1]==cor[j][1])&&(cor[g][1]==cor[k][1])&&(cor[g][0]==cor[j][0]))
			                 	{
			                 		cnt++;
			                 		juxing[cnt].area=(cor[i][1]-cor[k][1])*(cor[i][0]-cor[j][0]);
			                 		juxing[cnt].weizhi[1][1]=cor[i][1];juxing[cnt].weizhi[1][0]=cor[i][0];
			                 		juxing[cnt].weizhi[2][1]=cor[j][1];juxing[cnt].weizhi[2][0]=cor[j][0];
			                 		juxing[cnt].weizhi[3][1]=cor[k][1];juxing[cnt].weizhi[3][0]=cor[k][0];
			                 		juxing[cnt].weizhi[4][1]=cor[g][1];juxing[cnt].weizhi[4][0]=cor[g][0];
			                 	}
			                 	if((cor[i][1]==cor[g][1])&&(cor[j][1]==cor[k][1])&&(cor[j][0]==cor[g][0]))
			                 	{
			                 		cnt++;
			                 		juxing[cnt].area=(cor[i][1]-cor[k][1])*(cor[i][0]-cor[g][0]);
			                 		juxing[cnt].weizhi[1][1]=cor[i][1];juxing[cnt].weizhi[1][0]=cor[i][0];
			                 		juxing[cnt].weizhi[2][1]=cor[g][1];juxing[cnt].weizhi[2][0]=cor[g][0];
			                 		juxing[cnt].weizhi[3][1]=cor[k][1];juxing[cnt].weizhi[3][0]=cor[k][0];
			                 		juxing[cnt].weizhi[4][1]=cor[j][1];juxing[cnt].weizhi[4][0]=cor[j][0];
			                 	}
			                 }
			                 if(cor[i][0]==cor[g][0])
			                 {
			                 	if((cor[i][1]==cor[j][1])&&(cor[k][1]==cor[g][1])&&(cor[k][0]==cor[j][0]))
			                 	{
			                 		cnt++;
			                 		juxing[cnt].area=(cor[i][1]-cor[j][1])*(cor[i][0]-cor[k][0]);
			                 		juxing[cnt].weizhi[1][1]=cor[i][1];juxing[cnt].weizhi[1][0]=cor[i][0];
			                 		juxing[cnt].weizhi[2][1]=cor[j][1];juxing[cnt].weizhi[2][0]=cor[j][0];
			                 		juxing[cnt].weizhi[3][1]=cor[g][1];juxing[cnt].weizhi[3][0]=cor[g][0];
			                 		juxing[cnt].weizhi[4][1]=cor[k][1];juxing[cnt].weizhi[4][0]=cor[k][0];
			                 	}
			                 	if((cor[i][1]==cor[k][1])&&(cor[j][1]==cor[g][1])&&(cor[j][0]==cor[k][0]))
			                 	{
			                 		cnt++;
			                 		juxing[cnt].area=(cor[i][1]-cor[j][1])*(cor[i][0]-cor[k][0]);
			                 		juxing[cnt].weizhi[1][1]=cor[i][1];juxing[cnt].weizhi[1][0]=cor[i][0];
			                 		juxing[cnt].weizhi[2][1]=cor[k][1];juxing[cnt].weizhi[2][0]=cor[k][0];
			                 		juxing[cnt].weizhi[3][1]=cor[g][1];juxing[cnt].weizhi[3][0]=cor[g][0];
			                 		juxing[cnt].weizhi[4][1]=cor[j][1];juxing[cnt].weizhi[4][0]=cor[j][0];
			                 	}
			                 }
			         }
		    if(cnt<=1)
		    {
		    	printf("imp\n");
		    	scanf("%d",&n);
		    	continue;
		    }
			long long ans=0;
			for(int i=1;i<=cnt;i++)
			    for(int j=i+1;j<=cnt;j++) 
				{
					int ximax=max(juxing[i].weizhi[1][0],juxing[i].weizhi[2][0]);
					int ximin=min(juxing[i].weizhi[1][0],juxing[i].weizhi[2][0]);
					int yimax=max(juxing[i].weizhi[1][1],juxing[i].weizhi[3][1]);
					int yimin=min(juxing[i].weizhi[1][1],juxing[i].weizhi[3][1]);
					int xjmax=max(juxing[j].weizhi[1][0],juxing[j].weizhi[2][0]);
					int xjmin=min(juxing[j].weizhi[1][0],juxing[j].weizhi[2][0]);
					int yjmax=max(juxing[j].weizhi[1][1],juxing[j].weizhi[3][1]);
					int yjmin=min(juxing[j].weizhi[1][1],juxing[j].weizhi[3][1]);
					if((ximin>xjmax)||(xjmin>ximax)||(yimin>yjmax)||(yjmin>yimax))
					{
						if(ans<juxing[i].area+juxing[j].area)ans=juxing[i].area+juxing[j].area;
					}
					if((ximin>xjmin)&&(ximax<xjmax)&&(yimin>yjmin)&&(yimax<yjmax))
					{
						if(ans<juxing[j].area)ans=juxing[j].area;
					}
					if((ximin<xjmin)&&(ximax>xjmax)&&(yimin<yjmin)&&(yimax>yjmax))
					{
						if(ans<juxing[i].area)ans=juxing[i].area;
					}
				}
		    if(ans==0)
		    {
		    	printf("imp\n");
		    	scanf("%d",&n);
		    	continue;
		    }
		    printf("%I64d\n",ans);  
		    scanf("%d",&n);
	}
	return 0;
}

E - Song Jiang’s rank list
模拟,用结构体+自定义sort

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=300;
struct hero
{
	string name;
	int kill;
	int mar;
	int mir;
	bool operator <(const hero& b) const {
	if(kill==b.kill) return name<b.name;
	return kill>b.kill;
	}
};
hero h[maxn];
int n;
int main()
{
	while(1)
	{	
		
		scanf("%d",&n);
		if(!n) break;
		for(int i=1;i<=n;i++)
			{
				cin>>h[i].name>>h[i].kill;
				h[i].mir=1;
			}
		sort(h+1,h+1+n);
		h[0].kill=2147483647;
		for(int i=1;i<=n;i++)
		{
			cout<<h[i].name<<' '<<h[i].kill<<endl;
			if(h[i].kill==h[i-1].kill)  h[i].mir=h[i-1].mir+1; 
		//	printf("h   %d  %d\n",i,h[i].mir);
		}
		int q;
		scanf("%d",&q);
		for(int i=1;i<=q;i++)
		{	
			string s;
			cin>>s;
			for(int j=1;j<=n;j++)
				if(h[j].name==s)
				{	
					if(h[j].mir==1)
					printf("%d\n",j);
					else
					printf("%d %d\n",j-h[j].mir+1,h[j].mir);
				}
		}
	}
	return 0;
}

*I - Little Zu Chongzhi’s Triangles
此题队友用的是状态压缩DP,%%%
我的想法是根据海伦公式(S = sqrt(p * (p - a) * (p - b) * (p - c))),贪心求解

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>

using namespace std;

const int M=(1<<12);

struct node
{
	double area;
	int stick;
	node()
	{
		area=0;
		stick=0;
	}
}tri[300];
int n,sti[20],trn;
double f[222][M];

int change(int i,int j,int k)
{
	i--;j--;k--;
	return (1<<i)+(1<<j)+(1<<k);
}

double check(int i,int j,int k)
{
	double ret=0;
/*	double p=i+j+k;
	p/=2;
	ret=sqrt(p*(p-i)*(p-j)*(p-k));*/
	double angle=i*i+j*j-k*k;
	double aa=i*j;
	angle=angle/(2*aa);
	angle=sqrt(1-angle*angle);
	ret=0.5*aa*angle;
	return ret;
}

double maxx(double a,double b)
{
	if(a>b)return a;
    else return b;
}

int main()
{
	scanf("%d",&n);
	while(n)
	{
		memset(sti,0,sizeof(sti));
		memset(tri,0,sizeof(tri));
		for(int i=1;i<=n;i++)scanf("%d",&sti[i]);
		trn=0;
		for(int i=1;i<=n;i++)
		    for(int j=i+1;j<=n;j++)
		         for(int k=j+1;k<=n;k++)
		         {
		         	if(i!=j&&j!=k&&i!=k)
		         	{
		         		if((sti[i]+sti[j]>sti[k])&&(sti[i]+sti[k]>sti[j])&&(sti[k]+sti[j]>sti[i]))
		         		{
		         			trn++;
		         			tri[trn].stick=change(i,j,k);
		         			tri[trn].area=check(sti[i],sti[j],sti[k]);
		         		}
		         	}
		         }
		if(trn==0)
		{
			printf("0.00\n");
			scanf("%d",&n);
			continue;
		}
		if(trn==1)
		{
			printf("%.2lf\n",tri[1].area);
			scanf("%d",&n);
			continue;
		}
		memset(f,0,sizeof(f));
		int tem=(1<<n)-1;
		for(int i=1;i<=trn;i++)
		{
			for(int j=0;j<tem;j++)
			{
				f[i][j]=f[i-1][j];
				if(!(j&tri[i].stick))
				{
					f[i][j]=maxx(f[i-1][j],f[i-1][j^tri[i].stick]+tri[i].area);
				}
			}
		}
		double ans=0;
		for(int i=0;i<tem;i++)
		{
			ans=maxx(ans,f[trn][i]);
		}
		printf("%.2lf\n",ans);
		scanf("%d",&n);
	}
	return 0;
}

K - How Many Maos Does the Guanxi Worth
久违的图论
n最大才30,随便搞…
枚举每个点(1和n除外),删除该点求最短路径,求出这n-2个最短路径的值的最大值
最短路用迪杰斯特拉

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int ans;
const int maxm=2000;
const int maxn=50;
struct edges
{
	int w;
	int f; int t;
	int nx;
};
edges e[maxm];
int head[maxn];
bool vis[maxn];
long long dp[maxn];
int n,m;
long long dfs(int x,int y,int f)
{
	
	if(y==n) {
				return 0;
			}	
	vis[y]=1;
	for(int i=head[y];~i;i=e[i].nx)
	{	
		
		if(e[i].t!=f&&e[i].t!=x)
		{
			if(vis[e[i].t]) dp[y]=min(dp[y],dp[e[i].t]+e[i].w);
			else
			dp[y]=min(dp[y],e[i].w+dfs(x,e[i].t,y));	
		}		
	}
	return dp[y];
}
int main()
{
	while(cin>>n)
	{		
			
			int tot=0;
			memset(head,-1,sizeof(head));
			scanf("%d",&m);
			if(n==0&&m==0) break;
 			for(int i=1;i<=m;i++)
			{
				int a,b,c;
				scanf("%d%d%d",&a,&b,&c);
				tot++;
				e[tot].f=a; e[tot].t=b; e[tot].w=c;
				e[tot].nx=head[a]; head[a]=tot;
				tot++;
				e[tot].f=b; e[tot].t=a; e[tot].w=c;
				e[tot].nx=head[b]; head[b]=tot;			
			}
			long long ANS=0;
			for(int i=2;i<n;i++)
				 {	for(int j=1;j<=n;j++)
				 	dp[j]=2147483647;
				 	dp[n]=0;
				 	memset(vis,0,sizeof(vis));	
				 	dfs(i,1,-1);
					ANS=max(ANS,dp[1]);
				 }
			if(ANS>=2147483647) printf("Inf\n");
			else
			printf("%I64d\n",ANS);
	}
	return 0;
}

A - Dogs’ Candies
这个题有点坑…其实就是暴力,但一开始没注意时间,不敢下手。比赛期间没有做出来。后来发现时间是30s不是3s…论审题的重要性

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值