跳到正文

个人记录

世纪难题(假的)

MFn233约 7 分钟
原文
文章信息与版本

文章信息

收录
2026年8月13日
更新
2026年8月15日
篇幅
约 7 分钟

版本

  1. v1当前

A+B Problem

这是我的第一条博客,所以讲一些简简单单的东西(虽然有点简单过头了)

我们先来看看正常解法:

C++
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    cout << a+b << endl;
    return 0;
}
C
#include <stdio.h>

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d\n", a+b);
    return 0;
}

虽说给了示例代码就能混过关,但是我还是很想把代码尽量减少一点

using namespace省掉,直接不exit,然后把大括号也省略掉:

C++
#include<iostream>
int main()
{
	int a,b;
	while(std::cin>>a>>b)
		std::cout<<a+b<<std::endl;
}

或者也可以逝当压一压行(当然也不是很需要。。。)

C++
#include<iostream>
int main() { int a,b; while(std::cin>>a>>b) std::cout<<a+b<<std::endl; }

我实在发挥不了聪明才智了,因为这题目实在太无聊,太简单了。。。

所以,最后把最简c代码也附上:

C
#include <stdio.h>
int main()
{
  int a, b;
  while(scanf("%d %d", &a, &b)!=EOF)
  	printf("%d\n", a + b);
}

希望下次能讲一点有难度的。。

声明一下:不提交题解的原因是这题恶搞题解实在是太多了,一看很简单的问题结果题解长的离谱,后来官方把这道题设置为不能提交题解,并且提交了一个唯一正确题解:

C++
//本题的恶搞题解到此为止。

//为防止新人受到误导,不再接受新的此类题解。

//以前的保留不会删除,但请不要再提交。

#include <iostream>
#include <cstdio>

using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    cout << a+b;
    return 0;
}

也只能说秀儿太多,他们也只是为了搞笑,没想到真的误解了新人

有点像当年的图吧禁片了属于是

给大家看一下其中我觉得最秀的:

C++
//终于可以写一份A+B这么难的题的题解了。

//咦?竟然没有人写LCT的题解?

//Link-Cut Tree 会很伤心的!

//ORZ为了不让LCT伤心于是我来一份LCT的A+B题解吧!

//送上代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstring>
using namespace std;
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);
}
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()
{
    scanf("%d%d",&a,&b);
    node *A=getnew(a);
    node *B=getnew(b);
    //连边 Link
        connect(A,B);
    //断边 Cut
        cut(A,B);
    //再连边orz Link again
        connect(A,B);
    printf("%d\n",query(A,B)); 
    return 0;
}

真是秀的妈妈给秀开门,秀到家了

我也没想到这次会一写这么长,那就这样吧。我们下次再会

原谅我实在想不到该说什么结束语

原文
抓取于
  1. ManCity_Syh

    这属于盗取他人代码 劝删