Luogu P1001 A+B Problem
题目描述
输入两个整数a,b,输出它们的和(|a|,|b|<=10^9)。 注意 1、pascal使用integer会爆掉哦!
2、有负数哦!
3、c/c++的main函数必须是int类型,而且最后要return 0。这不仅对洛谷其他题目有效,而且也是noip/noi比赛的要求!
好吧,同志们,我们就从这一题开始,向着大牛的路进发。
“任何一个伟大的思想,都有一个微不足道的开始。”
输入输出格式
输入格式:
两个整数以空格分开
输出格式:
一个数
输入输出样例
20 30
50
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstring>
using namespace std;
struct node
{
int data,rev,sum;
node *son[],*pre;
bool judge();
bool isroot();
void pushdown();
void update();
void setson(node *child,int lr);
}lct[];
int top,a,b;
node *getnew(int x)
{
node *now=lct+ ++top;
now->data=x;
now->pre=now->son[]=now->son[]=lct;
now->sum=;
now->rev=;
return now;
}
bool node::judge(){return pre->son[]==this;}
bool node::isroot()
{
if(pre==lct)return true;
return !(pre->son[]==this||pre->son[]==this);
}
void node::pushdown()
{
if(this==lct||!rev)return;
swap(son[],son[]);
son[]->rev^=;
son[]->rev^=;
rev=;
}
void node::update(){sum=son[]->sum+son[]->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^],lr);
if(father->isroot()) now->pre=grandfa;
else grandfa->setson(now,father->judge());
now->setson(father,lr^);
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,);
}
return last;
}
void changeroot(node *now)
{
access(now)->rev^=;
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[]=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 ;
}//这个是搞笑的,下面的是真的,但是这个也可以对。就看你看不看得懂了
#include <iostream>
#include <cstdio> using namespace std; int main() {
int a,b;
cin >> a >> b;
cout << a+b;
return ;
}
Luogu P1001 A+B Problem的更多相关文章
- P1001 A+B Problem(int,long long)
题目描述 输入两个整数 a,b,输出它们的和(∣a∣,∣b∣≤109). 注意 Pascal 使用 integer 会爆掉哦! 有负数哦! C/C++ 的 main 函数必须是 int 类型,而且最后 ...
- 【题解】洛谷P1001 A+B Problem
第一篇博客,献给2020年的残夏. 静听8月的热情与安宁,在竞赛中的时光如白驹过隙. 也不惧未知的风雨,努力向着既往的通途. 题目地址 https://www.luogu.com.cn/problem ...
- 【luogu P1865 A % B Problem】 题解
题目链接:https://www.luogu.org/problemnew/show/P1865 其实就是埃拉托色尼筛素数模板... 好像每个数暴力枚举到sqrt()也可以...就算当我无聊练手罢 # ...
- P1001 A+B Problem (树链剖分)
这题考验我们构造模型的能力. 考虑构造一棵树,树上有3个节点,节点1和节点2连一条权值为a的边,节点1和节点3连一条权值为b的边,显然答案就是节点2到节点3的最短路径. 但这样还不够.考虑加法的性质, ...
- 洛谷 P1001 A+B Problem
题目描述 输入两个整数a,b,输出它们的和(|a|,|b|<=10^9). 注意 1.pascal使用integer会爆掉哦! 2.有负数哦! 3.c/c++的main函数必须是int类型,而且 ...
- 主席树 - Luogu 1001 A+B problem
看着大佬们的解法我瑟瑟发抖 我用主席树写一写吧 #include<iostream> #include<iomanip> #include<cmath> #incl ...
- 洛谷P1001 A+B Problem
这道题…………还是很简单!!! code: #include <iostream> #include <cstdio> using namespace std; int mai ...
- [Luogu] P1865 A % B Problem
题目描述 区间质数个数 输入输出格式 输入格式: 一行两个整数 询问次数n,范围m 接下来n行,每行两个整数 l,r 表示区间 输出格式: 对于每次询问输出个数 t,如l或r∉[1,m]输出 Cros ...
- luogu P1832 A+B Problem
题目背景 ·题目名称是吸引你点进来的 ·实际上该题还是很水的 题目描述 ·1+1=? 显然是2 ·a+b=? 1001回看不谢 ·哥德巴赫猜想 似乎已呈泛滥趋势 ·以上纯属个人吐槽 ·给定一个正整数n ...
随机推荐
- 不让bat文件运行命令结束后cmd窗口自动关闭
方法1假设你的bat名字叫aaa.bat你可以新开一个bat,内容是start aaa.bat然后这个新的bat是不会自动关闭的 方法2要执行bat后不退出,可以在bat里的最后添加pause命令,暂 ...
- JS常用方法(获取Class、获取元素样式、事件监听、cookie、ajax等)
var Util = {}; Util.byClass = function (oClass) {//全局获取 var tags = document.all ? document.all : doc ...
- AngularJS模块
方式一: <body ng-app="myApp"> <div ng-controller="myCtrl1"> <h1>{ ...
- 遇到ANDROID “call to opengl es api with no current context”错误
延迟线程执行 Timer timer=new Timer();//实例化Timer类 timer.schedule(new TimerTask(){ public void run(){ buyed( ...
- Linux进阶命令-sort、uniq、 cut、sed、grep、find、awk
命令难度总体来说有简入难,参数都是工作中常常用到的.如果涉及到一些生僻的参数还请百度或man一下. sort(参考学习网站:http://www.cnblogs.com/dong008259/arch ...
- javaWeb第一天
//第一个JavaWeb项目package com.chy.action; import java.io.IOException; import javax.servlet.ServletExcept ...
- H3CNE实验:通过Console端口本地访问H3C设备
连接好Console线后,将交换机开机,在SecureCRT上会显示如下信息: Starting...... RAMLine.....OK System is booting............. ...
- wget访问SOAP接口
SOAP协议主要是XML交互,所以其访问过程类似于这样: wget --header='Content-Type: text/xml;charset=utf-8' --post-data='<s ...
- Chrome浏览器扩展开发系列之十七:扩展中可用的chrome.events API
chrome.events中定义了一些常见的事件类型,可以供Chrome浏览器扩展程序发出对应的事件对象. 对于关注的事件,首先要通过addListener()在对应的事件上注册监听器,示例如下: c ...
- spring的applicationContext.xml配置SessionFactory抛异常
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFa ...