D1T1
题意:
给两种面值分别为a,b的纸币无限张,求最大的一个数,使得在不找零的情况下无法通过两种纸币的组合得到这个数。
分析:
1、设这个数为c,如果能组合出,那么有方程ax+by=c,题目保证了gcd(a,b)==1,所以c始终能被gcd(a,b)整除;
2、于是如果x,y可负,此方程一定有解。所以知道x或y为负的时候就是不符合的c;
3、要求最大的c,于是(x==-1,y==a-1)或(y==-1,x==b-1);
代码:
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
long long a,b,ans;
scanf("%lld%lld",&a,&b);
ans=b*(a-1)-a;
ans=max(ans,a*(b-1)-b);
printf("%lld",ans);
return 0;
}
D1T2
没写
D1T3
待补充
D2T1
分析:
简单的bfs
代码:
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
//#include <vector>
using namespace std;
typedef long long ll;
const int Tmax=1005;
ll h,r,x[Tmax],y[Tmax],z[Tmax];
int n;
bool G[Tmax][Tmax],v[Tmax];//vector<int> G[Tmax];
queue<int> Q;
double dist(int a,int b)
{
return sqrt(1.0*((x[a]-x[b])*(x[a]-x[b]))+1.0*(y[a]-y[b])*(y[a]-y[b])+1.0*(z[a]-z[b])*(z[a]-z[b]));
}
void work()
{
int i,tmp;
Q.push(0);
v[0]=true;
while(!Q.empty())
{
tmp=Q.front();
Q.pop();
for(i=1;i<=n+1;i++)
if(G[tmp][i]==true&&v[i]==false)
{
v[i]=true;
Q.push(i);
}
}
return;
}
int main()
{
int T,i,j;
scanf("%d",&T);
while(T--)
{
memset(G,0,sizeof(G));
memset(v,0,sizeof(v));
//while(!Q.empty()) Q.pop();
scanf("%d%lld%lld",&n,&h,&r);
for(i=1;i<=n;i++)
{
scanf("%lld%lld%lld",&x[i],&y[i],&z[i]);
if(z[i]-r<=0&&z[i]+r>=0) G[0][i]=G[i][0]=true;
if(z[i]-r<=h&&z[i]+r>=h) G[n+1][i]=G[i][n+1]=true;
}
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
if(dist(i,j)<=(double)(2.0*r)) G[i][j]=G[j][i]=1;
work();
if(v[n+1]==true) printf("Yes\n");
else printf("No\n");
}
return 0;
}
后续待补充。。。