过样例,print函数进制转换哪里错了
  • 板块P10510 进制
  • 楼主why0210
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/5/19 14:51
  • 上次更新2024/5/19 17:01:25
查看原帖
过样例,print函数进制转换哪里错了
1075600
why0210楼主2024/5/19 14:51
#include<bits/stdc++.h>
using namespace std;

using ll=long long;
const int N=60;
const ll inf=2e18;
ll x,m,a[N];
vector<ll>v;

void san(ll x)
{
	while(x)
	{
		v.push_back(x%3);
		x/=3;
	}
}

void print()
{
	ll res=0;
	for(ll i=0;i<=50;i++)
	{
		res+=pow(3,i)*a[i];//???
		//cout<<i<<':'<<res<<'\n';
	}
	cout<<res<<'\n';
}

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>x>>m;
    san(x);
    //cout<<v.size()<<'\n';
    //for(const auto &i:v)cout<<i<<' ';cout<<'\n'; 
    
    for(int i=0;i<v.size();i++)
    a[i]=v[i];
	//for(int i=0;i<=50;i++)cout<<a[i]<<' ';cout<<'\n';
	//print();
    while(m--)
    {
    	ll k,p;cin>>k>>p;
    	if(k==1)
    	{
    		if(a[p]==0)a[p]=1;
    		else if(a[p]==1)a[p]=2;
    		else if(a[p]==2)a[p]=0;
		}else if(k==2)
		{
			if(a[p]==0)a[p]=2;
			else if(a[p]==1)a[p]=0;
			else if(a[p]==2)a[p]=1;
		}else
		{
			if(a[p]==0)a[p]=0;
    		else if(a[p]==1)a[p]=2;
    		else if(a[p]==2)a[p]=1;
		}
		//for(int i=0;i<=50;i++)cout<<a[i]<<' ';cout<<'\n';
		print();
	}
    return 0;
}
/*
385170918681282722 1
2 18
385170918293862233
*/
2024/5/19 14:51
加载中...