又又又又又又逆天了?
2024-11-03 18:50:25
发布于:安徽
这段代码为我同学所做(已经同意)
别赖上我我写不出来这玩意
#include<bits/stdc++.h>
using namespace std;
string ss,ff,gg;
int kj[1000000];
int p[10000000];
int k[1000000];
int pio[10000000];
int jj[1000000];
int piu[10000000];
int sdg[1000000];
int qqq[10000000];
int pl(int a,int b){
    if(b==0)
        return a;
    else{
        int x,c;
        x=a^b;
        c=(a&b)<<1;
        return pl(x,c);
    }
}
void ip(int a){
    p[1]=1;
    for(int i=2;i<=sqrt(a);i++){
        if(p[i]==0){
        for(int j=i*i;j<=a;j+=i){
            p[j]=1;
        }}
    }
}
void add(string a,string b){
    int n[10000000]={0};
    int m[10000000]={0};
    int c[10000000]={0};
    long long answer=0;
    long long l1=a.size();
    long long l2=b.size();
    
    for(int i=0;i<l1;i++){
        n[l1-i-1]=a[i]-'0';  
    }
    
    for(int i=0;i<l2;i++){
        
        m[l2-i-1]=b[i]-'0';  
    }
    
    int l3;
    
    l3=max(l1,l2);
    for(int i=0;i<=l3;i++)
    {
        c[i]=c[i]+n[i]+m[i];
        if(c[i]>9){
            c[i+1]=1;
            c[i]%=10;
        }
    }
    while(c[l3]==0&&l3>=1)
    {
        l3--;
    }
    string an;
    for(int i=l3;i>=0;i--){
        an+=c[i]+'0';
    }
    
    for(int i=0;i<=l3;i++){
        cout<<an[i];
    }
    
    return;
    
}
int RAND_1(long long a,long long b){
    
    long long n = a + b;
    cout << n;
    return 0;
}
int RAND_2(string a, string b, int n[500], int m[500], int ans[501]){
    for(int i = 0; i < a.size(); i++)
    {
		n[i] = a[a.size() - i - 1] - '0';
    }
	for(int i = 0; i < b.size(); i++)
    {
		m[i] = b[b.size() - i - 1] - '0';
    }
    
	int len_maxn = max(a.size(), b.size()) + 1;
	for(int i = 0; i < len_maxn; i++)
	{
		ans[i] = n[i] + m[i] + ans[i];
        
		if(ans[i] > 9)
		{
			ans[i + 1]++;
			ans[i] = ans[i] % 10;
		}
	}
	while(ans[len_maxn - 1] == 0 && len_maxn > 0){
        
        len_maxn--;
    }
	for(int i = len_maxn - 1; i >= 0; i--){
        cout << ans[i];
    }
	return 0;
}
const int N=405;
struct Edge {
    int v,w;
};
vector<Edge> edge[N*N];
int n;
int dis[N*N];
bool vis[N*N];
struct cmp {
    bool operator()(int a,int b) {
        return dis[a]>dis[b];
    }
};
int Dijkstra(int start,int end)
{
    priority_queue<int,vector<int>,cmp> dijQue;
    memset(dis,-1,sizeof(dis));
    memset(vis,0,sizeof(vis));
    dijQue.push(start);
    dis[start]=0;
    while(!dijQue.empty()) {
        int u=dijQue.top();
        dijQue.pop();
        vis[u]=0;
        if(u==end)
            break;
        for(int i=0; i<edge[u].size(); i++) {
            int v=edge[u][i].v;
            if(dis[v]==-1 || dis[v]>dis[u]+edge[u][i].w) {
                dis[v]=dis[u]+edge[u][i].w;
                if(!vis[v]) {
                    vis[v]=true;
                    dijQue.push(v);
                }
            }
        }
    }
    return dis[end];
}
struct node 
{
    int data,rev,sum;
    node *son[2],*pre;
    bool judge();
    bool isroot();
    void pushdown();
    void update();
    void setson(node *child,int lr);
}lct[233];
int top,a,b;
node *getnew(int x)
{
    node *now=lct+ ++top;
    now->data=x;
    now->pre=now->son[1]=now->son[0]=lct;
    now->sum=0;
    now->rev=0;
    return now;
}
bool node::judge(){return pre->son[1]==this;}
bool node::isroot()
{
    if(pre==lct)return true;
    return !(pre->son[1]==this||pre->son[0]==this);
}
void node::pushdown()
{
    if(this==lct||!rev)return;
    swap(son[0],son[1]);
    son[0]->rev^=1;
    son[1]->rev^=1;
    rev=0;
}
void node::update(){sum=son[1]->sum+son[0]->sum+data;}
void node::setson(node *child,int lr)
{
    this->pushdown();
    child->pre=this;
    son[lr]=child;
    this->update();
}
void rotate(node *now)
{
    node *father=now->pre,*grandfa=father->pre;
    if(!father->isroot()){
        grandfa->pushdown();    
    }
    father->pushdown();now->pushdown();
    int lr=now->judge();
    father->setson(now->son[lr^1],lr);
    if(father->isroot()){
        now->pre=grandfa;
    }
    else{
        grandfa->setson(now,father->judge());
        }
    now->setson(father,lr^1);
    father->update();now->update();
    if(grandfa!=lct){
        grandfa->update();
    }
}
void splay(node *now)
{
    if(now->isroot()){
        return;
    }
    for(;!now->isroot();rotate(now)){
        if(!now->pre->isroot()){
            
    now->judge()==now->pre->judge()?rotate(now->pre):rotate(now);
        }
    }
}
node *access(node *now)
{
    node *last=lct;
    for(;now!=lct;last=now,now=now->pre)
    {
        splay(now);
        now->setson(last,1);
    }
    return last;
}
void changeroot(node *now)
{
    access(now)->rev^=1;
    splay(now);
}
void connect(node *x,node *y)
{
    changeroot(x);
    
    x->pre=y;
    access(x);
}
int man()
{
    int a,b,s=0,s1=0,i=0,na=0,nb=0;
    cin>>a>>b;
    if(a<=0) na=1,a*=-1;
    while(a!=0)
    {
        if(a%2!=0)
        s+=pow(2,a%2*i);
        a/=2;
        i++;
    }
    i=0;
    if(na==1) s*=-1;
    if(b<=0) nb=1,b*=-1;
    while(b!=0)
    {
        if(b%2!=0)
        s1+=pow(2,b%2*i);
        b/=2;
        i++;
    }
    if(nb==1) s1*=-1;
    cout<<s+s1;;
    return 0;
}
void cut(node *x,node *y)
{
    changeroot(x);
    access(y);
    
    splay(x);
    x->pushdown();
    x->son[1]=y->pre=lct;
    x->update();
}
int query(node *x,node *y)
{
    changeroot(x);
    node *now=access(y);
    return now->sum;
}
int main(){
    if(3423*0){
        scanf("%d%d",&a,&b);
        
        node *A=getnew(a);
        node *B=getnew(b);
        connect(A,B);
        cut(A,B);
        connect(A,B);
        printf("%d\n",query(A,B)); 
        return 0;
    }else if((2342|12)&0>>67){
        int a,b;
        scanf("%d%d",&a,&b);
        Edge Qpush;
        
        Qpush.v=1;
        Qpush.w=a;
        edge[0].push_back(Qpush);
        
        Qpush.v=2;
        Qpush.w=b;
        edge[1].push_back(Qpush);
        
        printf("%d",Dijkstra(0,2));
        return 0;
        
    }else if(1|2|3|4&0<<34>>5|4&&0){
        int a,b;
        cin >> a >> b;
        cout << pl(a,b) << endl;
        return 0;
        
    }else{
        int a;
        long long b;
        
        man();
    }
    return 0;
}
//抽象 :)
这里空空如也








有帮助,赞一个