Offer收割 程式設計練習賽15 B 分數調查

2021-09-29 01:27:33 字數 1087 閱讀 1382

【題目鏈結】:

【題意】

【題解】

帶權並查集

relation[x]表示父親節點比當前節點大多少;

對於輸入的x,y,z;

如果z小於0;

則交換x,y同時z取相反數;

然後按照帶權並查集的更新方式,對y的根節點的r2的relation[r2]進行更新即可;

【number ofwa】

0 【完整**】

#include 

using

namespace

std;

#define lson l,m,rt<<1

#define rson m+1,r,rt<<1|1

#define ll long long

#define rep1(i,a,b) for (int i = a;i <= b;i++)

#define rep2(i,a,b) for (int i = a;i >= b;i--)

#define mp make_pair

#define pb push_back

#define fi first

#define se second

#define ms(x,y) memset(x,y,sizeof x)

typedef pair pii;

typedef pairpll;

const

int dx[9] = ;

const

int dy[9] = ;

const

double pi = acos(-1.0);

const

int n = 100000+100;

const

int inf = 0x3f3f3f3f;

int n,m,q,f[n],relation[n];

int ff(int x)

int main()

int r1 = ff(x),r2 = ff(y);

if (r1!=r2)

}rep1(i,1,q)

}return

0;}

牛客網練習賽15 B

include includeusing namespace std define ll long long define inf 1e 5 const int inv2 500000004 const int inf 2147483647 const int max 100010 const in...

Offer收割 程式設計練習賽1

做了三題,題目都比較暴力。a題 題意 給你乙個三階的幻方,三階幻方指的是將1 9不重複的填入乙個3 3的矩陣當中,使得每一行 每一列和每一條對角線的和都是相同的。現在準備將乙個三階幻方中的一些陣列抹掉 0代替 交給你來進行還原,並且希望她能夠判斷出究竟是不是只有一組解。如果只有一組解,輸出該三階幻方...

Offer收割 程式設計練習賽7

比較容易想到是o n 2 的解決方案,遍歷n種刪除可能,每次遍歷o n 時間求總高度。前者優化比較困難,因而想辦法優化每次遍歷求高度的時間。由前往後遍歷,當刪除第i個時,先前的排版是連續的,從而通過計數器等累加方法可以求得已完整行的總高度presum,以及當前未完整行的w,h。include def...