目录
A.喜欢发财数的电子小偷
该题实际上是一个进制转化的问题,首先分析问题,遇到6和8时直接被偷走也就是跳过,也就是0-9中实际上只有八个数字0-7,其实这道题就是八进制转化为十进制的问题了,但是需要一些细节处理。该题将数据分为三部分0-5,7,9与实际上八进制的0-7不同,所以遇到7减1,遇到9减2,就可以改成0-7的范围,就可以直接开始进制转化
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef pair<int,int> PII;
typedef long long LL;
const int N=1e5+10;
void solve()
{
int n;
cin>>n;
int k=0;
int res=0;
while(n!=0)
{
int p=n%10;
if(p==7)p--;//遇到7减1
else if(p==9)p-=2;//遇见9减2
res+=p*pow(8,k);
n/=10;k++;
}
cout<<res<<'\n';
}
signed main()
{
IOS;
int t;
// t=1;//单组样例
cin>>t;//多组样例
while(t--)
{
solve();
}
return 0;
}
B.奇偶数
看似这道题是一个筛质数的题目,实际上不需要筛质数的操作,只需要将每个数的所有倍数标记一下,然后看数字是否被标记次数大于1,大于1则证明的该数字时可以有不同的数字想乘得到
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef pair<int,int> PII;
typedef long long LL;
const int N=5e6+10;
int a[N];
void solve()
{
int n;
cin>>n;
for(int i=2;i<=n;i++)
{
if(a[i]==0)
{
for(int j=i;j<=n;j+=i)a[j]++;
}
}
int res=0;
for(int i=1;i<=n;i++)if(a[i]>1)res++;
cout<<n-res-1<<'\n';
}
signed main()
{
IOS;
int t;
t=1;//单组样例
// cin>>t;//多组样例
while(t--)
{
solve();
}
return 0;
}
C.神奇作业
因为需要求最小的次数,所以可以先计算每个数被3一直除,除到零需要几次,只要有一个数除到零,则其他的数字就可以利用零来变成零
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef pair<int,int> PII;
typedef long long LL;
const int N=2e5+10;
vector<int> v;
int a[N];
int judge(int x)
{
int res=0;
while(x!=0)
{
x/=3;
res++;
// x=round(x);
}
return res;
}
void solve()
{
int l,r;
cin>>l>>r;
// cout<<a[3]<<" "<<a[l-1]<<'\n';
cout<<a[r]-a[l-1]+v[l]<<'\n';
}
signed main()
{
IOS;
int t;
// t=1;//单组样例
cin>>t;//多组样例
v.push_back(0);
for(int i=1;i<=200000;i++)v.push_back(judge(i));
for(int i=1;i<=200000;i++)a[i]+=a[i-1]+v[i];
while(t--)
{
solve();
}
return 0;
}
D.洗澡
判断每个区间之间的大小就行
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef pair<int,int> PII;
typedef long long LL;
const int N=1e5+10;
void solve()
{
int n,m,s;
cin>>n>>s>>m;
vector<pair<int,int>> v;
v.push_back({0,0});
for(int i=0;i<n;i++)
{
int a,b;
cin>>a>>b;
v.push_back({a,b});
}
v.push_back({m,m});
int x=0;
for(int i=1;i<=n+1;i++)
{
x=v[i].first-v[i-1].second;
// cout<<x<<"\n";
if(x>=s)
{
cout<<"YES\n";
return;
}
}
cout<<"NO\n";
return;
}
signed main()
{
IOS;
int t;
// t=1;//单组样例
cin>>t;//多组样例
while(t--)
{
solve();
}
return 0;
}
E.打牌
模拟题,把所有情况列出来就行
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef pair<int,int> PII;
typedef long long LL;
const int N=1e5+10;
void solve()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
int res=0;
if(a>c&&b>d)res++;
if(a>d&&b>c)res++;
if(b>c&&a>d)res++;
if(b>d&&a>c)res++;
if(a==c&&b>d)res++;
if(a==d&&b>c)res++;
if(a>c&&b==d)res++;
if(a>d&&b==c)res++;
if(b==c&&a>d)res++;
if(b==d&&a>c)res++;
if(b>c&&a==d)res++;
if(b>d&&a==c)res++;
cout<<res<<'\n';
}
signed main()
{
IOS;
int t;
// t=1;//单组样例
cin>>t;//多组样例
while(t--)
{
solve();
}
return 0;
}
F.矩阵
直接将所有的矩阵扫一遍即可
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=510;
signed main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
int a[N][N],b[N][N];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
char a1;
cin>>a1;
a[i][j]=a1-'0';
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
char b1;
cin>>b1;
b[i][j]=b1-'0';
}
}
for(int i=0;i<n-1;i++)
{
for(int j=0;j<m-1;j++)
{
if(a[i][j]!=b[i][j])
{
if(a[i][j]==0&&b[i][j]==1)
{
a[i][j]=(a[i][j]+1)%3;
a[i+1][j+1]=(a[i+1][j+1]+1)%3;
a[i+1][j]=(a[i+1][j]+2)%3;
a[i][j+1]=(a[i][j+1]+2)%3;
}
else if(a[i][j]==0&&b[i][j]==2)
{
a[i][j]=(a[i][j]+2)%3;
a[i+1][j+1]=(a[i+1][j+1]+2)%3;
a[i+1][j]=(a[i+1][j]+1)%3;
a[i][j+1]=(a[i][j+1]+1)%3;
}
else if(a[i][j]==1&&b[i][j]==0)
{
a[i][j]=(a[i][j]+2)%3;
a[i+1][j+1]=(a[i+1][j+1]+2)%3;
a[i+1][j]=(a[i+1][j]+1)%3;
a[i][j+1]=(a[i][j+1]+1)%3;
}
else if(a[i][j]==1&&b[i][j]==2)
{
a[i][j]=(a[i][j]+1)%3;
a[i+1][j+1]=(a[i+1][j+1]+1)%3;
a[i+1][j]=(a[i+1][j]+2)%3;
a[i][j+1]=(a[i][j+1]+2)%3;
}
else if(a[i][j]==2&&b[i][j]==1)
{
a[i][j]=(a[i][j]+2)%3;
a[i+1][j+1]=(a[i+1][j+1]+2)%3;
a[i+1][j]=(a[i+1][j]+1)%3;
a[i][j+1]=(a[i][j+1]+1)%3;
}
else if(a[i][j]==2&&b[i][j]==0)
{
a[i][j]=(a[i][j]+1)%3;
a[i+1][j+1]=(a[i+1][j+1]+1)%3;
a[i+1][j]=(a[i+1][j]+2)%3;
a[i][j+1]=(a[i][j+1]+2)%3;
}
}
}
}
bool flag=false;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(a[i][j]!=b[i][j])
{
flag=true;break;
}
}
if(flag==true)break;
}
if(flag==true)cout<<"NO\n";
else cout<<"YES\n";
}
return 0;
}
487

被折叠的 条评论
为什么被折叠?



