6 条题解
-
0
终于可以写一份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
from tkinter import * import tkinter.messagebox
color_number = 1 # 每次运行都是黑棋先走 size = 16 stop = 0
chess = [[0 for i in range(size + 1)] for i in range(size + 1)] def paint(event):
让棋子下在棋盘点上
global color_number
if event.x % 30 > 15: event.x = event.x // 30 + 1 else: event.x = event.x // 30 if event.y % 30 > 15: event.y = event.y // 30 + 1 else: event.y = event.y // 30 # 边缘检测 if event.x > size: event.x = size if event.y > size: event.y = size if event.x < 1: event.x = 1 if event.y < 1: event.y = 1 # 确定下棋坐标 x1, y1 = (event.x * 30 - 15), (event.y * 30 - 15) x2, y2 = (event.x * 30 + 15), (event.y * 30 + 15) if stop == 0: if chess[event.y][event.x] == 0: text1.delete("1.0", END) # 清空文本框 if color_number == 1: canvas.create_oval(x1, y1, x2, y2, fill="black", tags="oval") chess[event.y][event.x] = 1 color_number = 0 elif color_number == 0: canvas.create_oval(x1, y1, x2, y2, fill="white", tags="oval") chess[event.y][event.x] = 2 color_number = 1 printtable() # 输出二维数组 gameover(event.y, event.x)
def wininfo(): # 提示窗口 global stop tkinter.messagebox.showinfo("", "Game over") stop = 1 def gameover(xx, yy): count = 0 for i in range(xx + 1, 17): # 向右搜索 if chess[i][yy] == chess[xx][yy]: count += 1 else: break for i in range(xx, 0, -1): # 向左搜索 if chess[i][yy] == chess[xx][yy]: count += 1 else: break if count == 5: wininfo() count = 0
for i in range(yy + 1, 17): # 向下搜索 if chess[xx][i] == chess[xx][yy]: count += 1 else: break for i in range(yy, 0, -1): # 向上搜索 if chess[xx][i] == chess[xx][yy]: count += 1 else: break if count == 5: wininfo() count = 0 for i, j in zip(range(xx + 1, 17), range(yy + 1, 17)): # 向右下搜索 if chess[i][j] == chess[xx][yy]: count += 1 else: break for i, j in zip(range(xx, 0, -1), range(yy, 0, -1)): # 向左上搜索 if chess[i][j] == chess[xx][yy]: count += 1 else: break if count == 5: wininfo() count = 0 for i, j in zip(range(xx - 1, 0, -1), range(yy + 1, 17)): # 向左下搜索 if chess[i][j] == chess[xx][yy]: count += 1 else: break for i, j in zip(range(xx, 17), range(yy, 0, -1)): # 向右上搜索 if chess[i][j] == chess[xx][yy]: count += 1 else: break if count == 5: wininfo() count = 0
def reset(): global stop canvas.delete('oval') for i in range(size + 1): for j in range(size + 1): chess[i][j] = 0 text1.delete("1.0", END) # 清空文本框 printtable() # 输出二维数组 stop=0 top = Tk() top.title("五子棋") top.geometry("1000x525") canvas = Canvas(top, width=500, height=500) canvas.pack(expand=YES, fill=BOTH) canvas.bind("<Button-1>", paint) # 每次点击鼠标左键(事件),触发paint函数 for num in range(1, 17): canvas.create_line(num * 30, 30, num * 30, 480, width=2) for num in range(1, 17): canvas.create_line(30, num * 30, 480, num * 30, width=2) text1 = Text(top, width=51, height=18) text1.place(x=520, y=60, anchor='nw')
退出按钮
quit1 = Button(top, text="退出", command=top.quit, width=10, height=2) quit1.place(x=620, y=400, anchor='nw')
打印五子棋落子状态
def printtable(): for i in range(size + 1): text1.insert(INSERT, str(chess[i]) + "\n")
printtable()
二维数组标签
label1 = Label(top, text='chess数组内容:') label1.place(x=520, y=30, anchor='nw')
退出按钮
restart = Button(top, text="重置", command=reset, width=10, height=2) restart.place(x=520, y=400, anchor='nw')
top.mainloop()
-
-1
#include<bits/stdc++.h> using namespace std; int a,b; inline int read(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch==' ') w=-1; ch=getchar(); } while(ch>='0'&&ch<='9'){ s=s10+ch-'0'; ch=getchar(); } return sw; } inline void write(int x){ if(x<0){ putchar('-'); x=-x; } if(x>9) write(x/10); putchar(x%10+'0'); } void work(){ a=read(); b=read(); int c=a+b; write(c); } int main(){ work(); return 0; }
- 1
信息
- ID
- 9
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 4
- 标签
- 递交数
- 2062
- 已通过
- 877
- 上传者