A.Factory
相当于判断 a+=a%b 这个a的值会不会无限增加
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,m;
scanf("%d%d",&a,&m);
int ok=0;
if (m%a==0&&m>=a) m=m/a;
if (a>m&&a%m==0) ok=1;
while(m%2==0){
m=m/2;
}
if (m==1) ok=1;
if (ok) printf("Yes\n");
else printf("No\n");
return 0;
}
B. Valuable Resources
#include <bits/stdc++.h>
using namespace std;
#define maxn 1005
int a[maxn],b[maxn];
typedef long long ll;
int main()
{
int n;scanf("%d",&n);
int min1=1000000009;
int max1=-min1;
int min2=min1;
int max2=-min2;
for (int i=0;i<n;i++)
{
scanf("%d%d",&a[i],&b[i]);
min1=min(min1,min(a[i],a[i]));
max1=max(max1,max(a[i],a[i]));
min2=min(min2,min(b[i],b[i]));
max2=max(max2,max(b[i],b[i]));
}
ll mixx=max(max1-min1,max2-min2);
printf("%I64d\n",mixx*mixx);
return 0;
}
贪心没什么好说的了
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n;scanf("%I64d",&n);
ll s=1;
while(n--){
ll l,r;
scanf("%I64d%I64d",&l,&r);
for (ll i=0;;i++){
if (l > (r-(s<<i))){
break;
}
if (!((l>>i)&s)) l=(l+(s<<i));
}
printf("%I64d\n",l);
}
return 0;
}
预处理出每个值左边最近的一个值
#include <bits/stdc++.h>
using namespace std;
#define maxn 200005
int a[maxn];
int d[maxn*10];
int na[maxn*10];
int main()
{
memset(d,0,sizeof(d));
int n;scanf("%d",&n);
for (int i=0;i<n;i++){
scanf("%d",&a[i]);
d[a[i]]=1;
}
for (int i=1;i<=2000000;i++){
if (d[i-1]) na[i]=i-1;
else na[i]=na[i-1];
}
int ans=0;
for (int i=2;i<1000000;i++){
if (d[i]&&ans<(i-1)){
for (int s=i*2;s<1000000+i;s+=i){
ans=max(ans,na[s]%i);
if (ans==i-1) break;
}
}
}
printf("%d\n",ans);
return 0;
}