csp模擬賽5 加減法 寬搜維護聯通快

2022-05-27 16:57:13 字數 863 閱讀 8593

題目大意:

一開始想用並查集,發現很難維護聯通塊的代表元素,所以用了寬搜,開陣列會炸,所以開乙個優先佇列維護,每掃完乙個聯通塊,統計答案,清空優先佇列,!!千萬記住注意陣列的大小!!!

**:

#include#include#include#include#include#include#define int long long

#define n 1005000

using namespace std;

int n,m,l,val[n],head[n],cnt,tot,ans;

int siz[n];

bool vis[n];

struct nodee[n];

int read()

while(ch>='0'&&ch<='9')

return x*f;

}void add(int from,int to)

; head[from]=cnt;

}queueq;

priority_queue dij;

void bfs(int x)

} }while(siz)

if(siz>(l-1))

}while(dij.size()) dij.pop();

}signed main()

for(int i=1;i<=n;i++)if(!vis[i])bfs(i);

printf("%lld\n",ans);

fclose(stdin);fclose(stdout);

return 0;

}

時間加減法

include stdafx.h include windows.h typedef struct tagmydate mydate 用於表示兩個時間之間的差值,負值表示慢,正值表示快 typedef struct tagtimedistance timedistance int month day...

時間加減法

1.相關資料結構 首先看time.h檔案中隊time t的定義 可以看出time t實際上是乙個整數,它記錄了儲存的是從1970年1月1日0時0分0 秒到現在經過的秒數。這裡有一點要注意,對time t資料型別的值來說,它所表示的時間不能晚於2038年1月18日19時14分07秒,否則會發生溢位。為...

分數加減法

描述 編寫乙個c程式,實現兩個分數的加減法 輸入輸入包含多行資料 每行資料是乙個字串,格式是 a boc d 其中a,b,c,d是乙個0 9的整數。o是運算子 或者 資料以eof結束 輸入資料保證合法 輸出對於輸入資料的每一行輸出兩個分數的運算結果。注意結果應符合書寫習慣,沒有多餘的符號 分子 分母...