swifties270

931

lycc
Frederick.

yxc
Estrus_
x1nxinlan

itdef

konng

Bisector
SELFIE1

rhf

swifties270
4小时前
class Solution {
public:
bool isPopOrder(vector<int> pushV,vector<int> popV) {
stack<int>stk;
int i=0;//是pov序列的数的下标
for(auto x :pushV){
stk.push(x);//无脑入栈
while(stk.size()&&stk.top()==pushV[i]){//如果栈顶元素和出栈序列访问的值一样就要出栈
i++;
stk.pop();
}
}
if(stk.size()) return false;
}
};


swifties270
5小时前
class MinStack {
public:
/** initialize your data structure here. */
stack<int>stk1;
stack<int>stk2;//存最小值的
MinStack() {

}

void push(int x) {
stk1.push(x);
if(stk2.empty()||stk2.top()>=x)stk2.push(x);
}

void pop() {
if(stk1.top()==stk2.top()) stk2.pop();
stk1.pop();
}

int top() {
return stk1.top();
}

int getMin() {
return stk2.top();
}
};

/**
* Your MinStack object will be instantiated and called as such:
* MinStack obj = new MinStack();
* obj.push(x);
* obj.pop();
* int param_3 = obj.top();
* int param_4 = obj.getMin();
*/


swifties270
6小时前
class Solution {
public:
int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
vector<int> printMatrix(vector<vector<int> > matrix) {
vector<int> vec;
if (!matrix.size()) return vec;
int n=matrix.size(),m=matrix[0].size();
// printf("%d %d\n",n,m);
//   vector<int>vec;
// if(!n) return vec;
vector<vector<bool> >vis(n,vector<bool>(m,false));
int x=0,y=0,d=0;
for(int i=1;i<=n*m;i++){
vec.push_back(matrix[x][y]);
vis[x][y]=true;
int xx=x+dir[d][0],yy=y+dir[d][1];
if(xx<0||xx>=n||yy<0||yy>=m||vis[xx][yy]){
d=(d+1)%4;
xx=x+dir[d][0],yy=y+dir[d][1];
//vis[xx][yy]=true;
}
x=xx,y=yy;
//printf("%d %d\n",x,y);
}
return vec;
}
};


swifties270
7小时前
/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool isSymmetric(TreeNode* root) {
if(root==NULL) return true;
// if(root->left->val!=root->right->val)  return false;
return dfs(root->left,root->right);
}
bool dfs(TreeNode * root1,TreeNode * root2){
if(!root2&&root1) return false;
if (!root1&&root2) return false;
if(root1->val!=root2->val) return false;
return dfs(root1->left,root2->right)&&dfs(root1->right,root2->left);

}
};


swifties270
7小时前

/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool isSymmetric(TreeNode* root) {
if(!root) return true;
return dfs(root->left,root->right);
}
bool dfs(TreeNode *p,TreeNode *q){
if(!p&&q) return false;
if (!q&&p) return false;
if(p->val!=q->val) return false;
return dfs(p->left,q->right)&&dfs(p->right,q->left);

}
};


swifties270
7小时前
/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
void mirror(TreeNode* root) {
if(!root) return;
mirror(root->left);
mirror(root->right);
swap(root->left,root->right);
}

};


swifties270
8小时前
/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool hasSubtree(TreeNode* pRoot1, TreeNode* pRoot2) {
if(!pRoot1||!pRoot2) return false;
if(ispart(pRoot1,pRoot2)) return true;
return hasSubtree(pRoot1->left,pRoot2)||hasSubtree(pRoot1->right,pRoot2);
//相当于字符串匹配，a中第一个和b匹配
}
bool ispart(TreeNode *pRoot1,TreeNode *pRoot2){
if(!pRoot2) return true;
if(!pRoot1||pRoot1->val!=pRoot2->val) return false;
return ispart(pRoot1->left,pRoot2->left)&&ispart(pRoot1->right,pRoot2->right);

}
};


swifties270
8小时前
/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* merge(ListNode* l1, ListNode* l2) {
ListNode *p=new ListNode(0);
ListNode *q=p;
while(l1&&l2){
if(l1->val<l2->val) {
q->next=l1;
l1=l1->next;
}else{
q->next=l2;
l2=l2->next;
}
q=q->next;
}
while(l1){
q->next=l1;
l1=l1->next;
q=q->next;
}
while(l2){
q->next=l2;
l2=l2->next;
q=q->next;
}
return p->next;
}
};


/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
//从next开始递归反转
ListNode *rev=reverseList(next);//rev 就是反转从next到尾节点后的链表
return rev;

}
};


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>vec;
ll res1;
bool cmp(ll x,ll y){
return x>y;
}
void init(){
for(ll i=1;i<=1e12;i*=6) vec.push_back(i);
for(ll i=9;i<=1e12;i*=9) vec.push_back(i);
sort(vec.begin(),vec.end(),cmp);
}
void dfs(ll res,ll pos,ll ans){//还有res要凑,pos访问到的位置,ans是用了多少的数
if(pos==vec.size()){
res1=min(res1,ans);
return ;
}
if(ans+res/vec[pos]>=res1) return ;
for(int i=res/vec[pos];i>=0;i--){//当res=200 是pos是0时 vec[0]>200 进入到了dfs(200,1,0)
dfs(res-i*vec[pos],pos+1,ans+i);//i=200/81 就意味着可以选2个81或者1个81
}
}
int main(){
int t;
scanf("%d",&t);
init();
while(t--){
ll x;
scanf("%lld",&x);
res1=10000;
dfs(x,0,0);
printf("%lld\n",res1);
}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>vec;
ll res1=0;
bool cmp(ll x,ll y){
return x>y;
}
void init(){
for(ll i=1;i<=1e12;i*=6) vec.push_back(i);
for(ll i=9;i<=1e12;i*=9) vec.push_back(i);
sort(vec.begin(),vec.end(),cmp);
//  printf("%d\n",vec.size());
//for(int i=0;i<vec.size();i++)  printf("%lld ",vec[i]);
}
void dfs(ll res,ll pos,ll ans){//还有res要凑,pos访问到的位置,ans是用了多少的数
//printf("%d %d %d\n",res,pos,res1);
if(pos==vec.size()-1){
res1=min(res1,ans+res);
return ;
}
if(ans+res/vec[pos]>=res1) return ;
for(int i=res/vec[pos];i>=0;i--){//当res=200 是pos是0时 vec[0]>200 进入到了dfs(200,1,0)
dfs(res-i*vec[pos],pos+1,ans+i);//i=200/81 就意味着可以选2个81或者1个81
}
}
int main(){
int t;
scanf("%d",&t);
init();
while(t--){
ll x;
scanf("%lld",&x);
res1=10000;
dfs(x,0,0);
printf("%lld\n",res1);
}
}