1. 程式人生 > >NOIP2017 提高組部分題解

NOIP2017 提高組部分題解

小凱的疑惑

題目

https://www.luogu.org/problemnew/show/P3951

程式碼

#include<bits/stdc++.h>
using namespace std;
int main()
{
	//freopen("math.in","r",stdin);
	//freopen("math.out","w",stdout);
	long long a,b;
	cin>>a>>b; 
	long long n=a*b-a-b;
	cout<<n<<endl;
	return 0;
}

乳酪

題目

https://www.luogu.org/problemnew/show/P3958

程式碼

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
	ll f=1,num=0;
	char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1;ch=getchar(); }
	while (ch>='0'&&ch<='9') num=(num<<
1)+(num<<3)+ch-'0',ch=getchar(); return num*f; } const int maxnum=1e3+10; ll t,n,h,r,tot,x[maxnum],y[maxnum],z[maxnum]; ll head[maxnum],ver[maxnum*maxnum],Next[maxnum*maxnum]; bool flag; void add(int x,int y) { ver[++tot]=y,Next[tot]=head[x],head[x]=tot; } bool v[maxnum]; void dfs(int s) { if
(s==n+1) { flag=1; return ; } for (int i=head[s];i;i=Next[i]) { if (!v[ver[i]]) v[ver[i]]=1,dfs(ver[i]); } return ; } int main() { t=read(); while (t--) { memset(head,0,sizeof(head)); memset(ver,0,sizeof(ver)); memset(Next,0,sizeof(Next)); n=read(),h=read(),r=read(); for (int i=1;i<=n;i++) x[i]=read(),y[i]=read(),z[i]=read(); for (int i=1;i<=n;i++) for (int j=i+1;j<=n;j++) if (2*r>=sqrt(1.0*(x[i]-x[j])*(x[i]-x[j])+1.0*(y[i]-y[j])*(y[i]-y[j]) +1.0*(z[i]-z[j])*(z[i]-z[j]))) add(i,j),add(j,i); for (int i=1;i<=n;i++) if (r>=z[i]) add(0,i),add(i,0); for (int i=1;i<=n;i++) if (z[i]+r>=h) add(i,n+1),add(n+1,i); memset(v,0,sizeof(v)); v[0]=1,flag=0; dfs(0); if (flag) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }