程式設計之美初賽第二場

2022-05-13 20:49:35 字數 1650 閱讀 8740

problem a

一邊輸入邊一邊維護殘留網路,然後跑isap。小資料過了,大資料tle。據說可以bfs預處理 層次網路。可以過。 

view code

#include#include

#include

#include

using

namespace

std;

const

int inf = 10000000

;const

int maxn = 500

;#define min(a,b) (a)

#define max(a,b) (a)>(b)?(a):(b)

intk, c, m, s, t, n, n;

intmp[maxn][maxn];

inthead[maxn], idx, vh[maxn], h[maxn];

struct

nodeedge[maxn*maxn];

void addedge( int u, int v, int

f )

int dfs(int u,int

flow )

}for(int i = head[u]; ~i; i =edge[i].nxt )

if( edge[i].f ) tmp =min( tmp, h[ edge[i].v ] );

if( !( --vh[ h[u] ] ) ) h[s] =n;

else ++vh[ h[u] = tmp+1

];

return flow-remain;

}int

sap()

intmain()

}return

0;

}

problem c

因為點只能在 y = 0 的軸上,其他點到當前點的距離則成為乙個二次函式,開口向上。所以可以得出最小點即為我們所求。

所以可以三分求解。

view code

#include#include

#include

#include

using

namespace

std;

const

double eps = 1e-8

;const

double max =1e10;

const

int n = 50005

;struct

pointp[n];

intn;

int sgn(double

x)double fabs(double

x)double

dist( point a, point b )

double function(double

x)

return

res;

}int

main()

double

m, tm;

while( (r-l)>eps )

double ans =function(m);

printf(

"case #%d: %.6f\n

",ncase, m);

}

return0;

}

2014程式設計之美初賽第二場

時間限制 2000ms 單點時限 1000ms 記憶體限制 256mb 大神同學是乙個熱愛數字的孩子,她無時無刻不在思考生活與數學的聯絡。有一天,她發現其實公曆的設計是有講究的。每4年就會多閏一天,每一百年又會有一年不是閏年,而第四百年又是閏年。這樣,這四百年的週期裡每一年平均有365又400分之9...

程式設計之美初賽第二場 集合

時間限制 12000ms 單點時限 6000ms 記憶體限制 256mb 統計滿足下列條件的集合對 a,b 的數量 因為答案可能很大,你只需要求出它除以m的餘數。第一行乙個整數t 1 t 10 表示資料組數。接下來是t組輸入資料,測試資料之間沒有空行。每組資料格式如下 僅一行,2個整數n和m 1 m...

2014程式設計之美初賽第二場

時間限制 2000ms 單點時限 1000ms 記憶體限制 256mb 大神同學是乙個熱愛數字的孩子。她無時無刻不在思考生活與數學的聯絡。有一天,她發現事實上公曆的設計是有講究的。每4年就會多閏一天,每一百年又會有一年不是閏年。而第四百年又是閏年。這樣。這四百年的週期裡每一年平均有365又400分之...