T1:
本题给出,求出二元组的数量,满足
我们知道:
那么我们在与之间枚举即可。
我还增加了优化:
因为和肯定是的倍数,所以我们可以直接枚举一个,令。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
//const int mx;
int x,y;
ll ans=0;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>x>>y;
for(ll i=1;i*x<=y;i++)
{
if(y%(i*x)==0 && __gcd(i,y/i/x)==1)
{
ans++;
// cout<<i*x<<' '<<y/i<<'\n';
}
// cout<<i*x<<' '<<y/i<<' '<<__gcd(i*x,y/i)<<'\n';
}
cout<<ans<<'\n';
return 0;
}
/*
*/
T2:
我们看题:
本题是一道模拟题,我们按步骤模拟即可。
#include<bits/stdc++.h>
using namespace std;
const int mx=15;
int n;
char a[mx][mx],b[mx][mx],c[mx][mx][mx];
struct node{
int x,y;
}to[mx][mx],to2[mx][mx];//旋转90° ,左右对称
void turn(int k)//顺时针旋转90°
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
c[k%2][to[i][j].x][to[i][j].y]=c[(k-1)%2][i][j];
}
}
// for(int i=1;i<=n;i++)
// {
// for(int j=1;j<=n;j++)
// {
// cout<<c[i][j];
// }
// cout<<'\n';
// }
}
void work()//初始化
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
c[0][i][j]=a[i][j];
}
}
}
bool check(int k)//检查
{
k%=2;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(c[k][i][j]!=b[i][j])
{
return false;
}
}
}
return true;
}
void work2()//映射数组构造
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
to[i][j]={j,n-i+1};
to2[i][j]={i,n-j+1};
}
}
}
void turn2(int k)//左右对称
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
c[k%2][to2[i][j].x][to2[i][j].y]=c[(k-1)%2][i][j];
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>b[i][j];
}
}
//以上是输入输出
work2();
//以上是映射数组构造
work();
turn(1);
// for(int i=1;i<=n;i++)
// {
// for(int j=1;j<=n;j++)
// {
// cout<<c[1][i][j];
// }
// cout<<'\n';
// }
if(check(1))
{
cout<<1<<'\n';
return 0;
}
//以上是【操作一】的判断
turn(2);
if(check(2))
{
cout<<2<<'\n';
return 0;
}
//以上是【操作二】的判断
turn(3);
if(check(3))
{
cout<<3<<'\n';
return 0;
}
//以上是【操作三】的判断
work();
turn2(1);
if(check(1))
{
cout<<4<<'\n';
return 0;
}
//以上是【操作四】的判断
turn(2);
if(check(2))
{
cout<<5<<'\n';
return 0;
}
turn(3);
if(check(3))
{
cout<<5<<'\n';
return 0;
}
turn(4);
if(check(4))
{
cout<<5<<'\n';
return 0;
}
//以上是【操作五】的判断
work();
if(check(0))
{
cout<<6<<'\n';
return 0;
}
//以上是【啥都不变】的判断
cout<<7<<'\n';
//不能变成能目标
return 0;
}
/*
*/T3:
本题我们可以得到结论,直接差分。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mx=100005;
ll n,x,y;
ll a[mx],d[mx];
int main()//signed
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
d[i]=a[i]-a[i-1];
if(i==1)
{
continue;
}
if(d[i]>0)
{
x+=d[i];
}
else
{
y-=d[i];
}
}
cout<<max(x,y)<<'\n'<<abs(x-y)+1;
return 0;
}
/*
*/T4:
本题我们记忆化搜索,只需要细节。
#include<bits/stdc++.h>
using namespace std;
//#define int long long
//#define ll long long
//#define int unsigned long long
//#define ull unsigned long long
//#define int unsigned int
//#define ui unsigned int
#define int unsigned long long
//#define i128 __int128
//#define int double
//#define db double
//#define fr first
//#define se second
int read()
{
int ans=0,f=1;
char x=' ';
while(x<'0' || x>'9')
{
if(x=='-')
{
f=-1;
}
x=getchar();
}
while(x>='0' && x<='9')
{
ans=ans*10+x-'0';
x=getchar();
}
return ans*f;
}
void write(int x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9)
{
write(x/10);
}
putchar(x%10+'0');
}
//const int mx=;
const int mx=1e18;
map<int,int>mp;
int n,a,b,c,d;
int dfs(int u)
{
if(mp.count(u))
{
return mp[u];
}
int ans=d*u;
if(u%2==1)
{
ans=min(ans,min(dfs((u-(u%2))/2),dfs((u+2-u%2)/2))+a+d);
}
else
{
ans=min(ans,dfs(u/2)+a);
}
if(u%3!=0)
{
ans=min(ans,min(dfs((u-(u%3))/3)+u%3*d,dfs((u+3-u%3)/3)+(3-u%3)*d)+b);
}
else
{
ans=min(ans,dfs(u/3)+b);
}
if(u%5!=0)
{
ans=min(ans,min(dfs((u-(u%5))/5)+u%5*d,dfs((u+5-u%5)/5)+(5-u%5)*d)+c);
}
else
{
ans=min(ans,dfs(u/5)+c);
}
mp[u]=ans;
return ans;
}
signed main()//signed
{
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// cout.tie(nullptr);
int t;
t=read();
while(t--)
{
n=read();
a=read();
b=read();
c=read();
d=read();
mp.clear();
mp[0]=0;
mp[1]=d;
write(dfs(n));
cout<<'\n';
}
return 0;
}
/*
*/(谁会想到这么大的数据范围用记忆化搜索啊!)