From c22c620280c911f93f2aedd67f9247981b4ea468 Mon Sep 17 00:00:00 2001 From: apple Date: Sat, 30 Mar 2019 18:48:52 +0530 Subject: [PATCH] add codes --- 16diagonals.py | 58 + 2ndBestMST.cpp | 88 ++ 2seals.cpp | 58 + A-large-practice.in | 101 ++ A-small-practice.in | 101 ++ AA.out | 100 ++ B-large-practice.in | 201 +++ B-small-practice.in | 201 +++ BB.out | 100 ++ HLD/a.out | Bin 0 -> 20040 bytes HLD/easy_to_code_subtree_queries.cpp | 44 + HLD/lomsat_gelral.cpp | 57 + a.out | Bin 0 -> 35220 bytes artful_expediant.cpp | 30 + bargain | Bin 0 -> 21228 bytes bargaining_table.cpp | 36 + birds.cpp | 26 + colorfulPoints.cpp | 34 + convenient.cpp | 29 + demo.cpp | 9 + ehabAndMahmoudArray.cpp | 40 + even_digits.cpp | 56 + fair_game.cpp | 31 + fair_nut.cpp | 50 + fifa_fafa.cpp | 164 +++ gen.cpp | 24 + geometry.cpp | 119 ++ guessTheNumber.cpp | 24 + indent | Bin 0 -> 16688 bytes input.in | 2001 ++++++++++++++++++++++++++ laser.cpp | 36 + lecture_sleep.cpp | 34 + lids.cpp | 81 ++ lucky-dip.cpp | 51 + magicNums.cpp | 31 + milking_order.cpp | 88 ++ mountains.cpp | 35 + mst | Bin 0 -> 26804 bytes out_of_sorts.cpp | 36 + polycarp_and_letters.cpp | 22 + python_indentation.cpp | 49 + q_number_of_palin.cpp | 35 + rest_stops.cpp | 30 + rmq.cpp | 96 ++ round_subset.cpp | 40 + sort.in | 6 + sort.out | 6 + sorts.in | 6 + star_sky.cpp | 31 + swap_adjacent.cpp | 28 + uva260.cpp | 65 + uva352.cpp | 71 + vacation.cpp | 31 + way_to_home.cpp | 24 + 54 files changed, 4714 insertions(+) create mode 100644 16diagonals.py create mode 100644 2ndBestMST.cpp create mode 100644 2seals.cpp create mode 100644 A-large-practice.in create mode 100644 A-small-practice.in create mode 100644 AA.out create mode 100644 B-large-practice.in create mode 100644 B-small-practice.in create mode 100644 BB.out create mode 100755 HLD/a.out create mode 100644 HLD/easy_to_code_subtree_queries.cpp create mode 100644 HLD/lomsat_gelral.cpp create mode 100755 a.out create mode 100644 artful_expediant.cpp create mode 100755 bargain create mode 100644 bargaining_table.cpp create mode 100644 birds.cpp create mode 100644 colorfulPoints.cpp create mode 100644 convenient.cpp create mode 100644 demo.cpp create mode 100644 ehabAndMahmoudArray.cpp create mode 100644 even_digits.cpp create mode 100644 fair_game.cpp create mode 100644 fair_nut.cpp create mode 100644 fifa_fafa.cpp create mode 100644 gen.cpp create mode 100644 geometry.cpp create mode 100644 guessTheNumber.cpp create mode 100755 indent create mode 100644 input.in create mode 100644 laser.cpp create mode 100644 lecture_sleep.cpp create mode 100644 lids.cpp create mode 100644 lucky-dip.cpp create mode 100644 magicNums.cpp create mode 100644 milking_order.cpp create mode 100644 mountains.cpp create mode 100755 mst create mode 100644 out_of_sorts.cpp create mode 100644 polycarp_and_letters.cpp create mode 100644 python_indentation.cpp create mode 100644 q_number_of_palin.cpp create mode 100644 rest_stops.cpp create mode 100644 rmq.cpp create mode 100644 round_subset.cpp create mode 100644 sort.in create mode 100644 sort.out create mode 100644 sorts.in create mode 100644 star_sky.cpp create mode 100644 swap_adjacent.cpp create mode 100644 uva260.cpp create mode 100644 uva352.cpp create mode 100644 vacation.cpp create mode 100644 way_to_home.cpp diff --git a/16diagonals.py b/16diagonals.py new file mode 100644 index 0000000..e1de8ed --- /dev/null +++ b/16diagonals.py @@ -0,0 +1,58 @@ +g = [[-1]*5 for i in range(5)] +def poss(c, i, j): + if c == '\\': + if i>0 and g[i-1][j] == '/': + return False + if j>0 and g[i][j-1] == '/': + return False + if i > 0 and j > 0 and g[i-1][j-1] == '\\': + return False + if i < 4 and j < 4 and g[i+1][j+1] == '\\': + return False + else: + if i>0 and g[i-1][j] == '\\': + return False + if j>0 and g[i][j-1] == '\\': + return False + if i > 0 and j > 0 and g[i-1][j-1] == '/': + return False + if i < 4 and j < 4 and g[i+1][j+1] == '/': + return False + return True +mx = 0 + +def printG(): + for row in g: + print(row) + +def kill(i, j, sol, size): + global mx, g + # mx = max(mx, len(sol)) + if len(sol) == size: + print(g) + return + if i >= 5 or j >= 5 or (i, j) in sol: + return + print (i, j) + # printG() + c = g[i][j] + if poss('/', i, j): + sol.append((i, j)) + g[i][j] = '/' + kill(i+1, j, sol, size) + kill(i, j+1, sol, size) + # g[i][j] = c + sol.pop(-1) + if poss('\\', i, j): + sol.append((i, j)) + g[i][j] = '\\' + kill(i+1, j, sol, size) + kill(i, j+1, sol, size) + # g[i][j] = c + sol.pop(-1) + + kill(i+1, j, sol, size) + kill(i, j+1, sol, size) + g[i][j] = c +kill(0, 0, [], 16) +# print(mx) \ No newline at end of file diff --git a/2ndBestMST.cpp b/2ndBestMST.cpp new file mode 100644 index 0000000..bbb988b --- /dev/null +++ b/2ndBestMST.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +using namespace std; +const int nax = (int)1e3 + 5; +int par[nax][23], mx[nax][23], level[nax]; +int LG; +vector > g[nax]; + +void dfs(int s, int p, int w) { + par[s][0] = p, mx[s][0] = w; + for (int lg=1; lg=0; i--) { + if (diff & (1<=0; i--) { + if (par[u][i] != par[v][i]) { + u = par[u][i], v = par[v][i]; + } + } + return par[u][0]; +} + +// u -> from, v -> to +int max_query(int u, int v) { + if (level[u] < level[v]) swap(u, v); + int diff = level[u] - level[v]; + int ans = 0; + for (int i=LG; i>=0; i--) { + if (diff & (1<=0; i--) { + if (par[u][i] != par[v][i]) { + ans = max(ans, max(mx[u][i], mx[v][i])); + u = par[u][i], v = par[v][i]; + } + } + return max(ans, mx[u][0]); +} + +int main() { + int n, m, u, v, w; + cin >> n >> m; + for (int i=0; i> u >> v >> w; + g[u].push_back(make_pair(v, w)); + g[v].push_back(make_pair(u, w)); + } + while ((1 << LG) < n) LG += 1; + dfs(1, 0, 0); + cin >> u >> v; + while (u != -1) { + int _lca = lca(u, v); + int ans = max(max_query(u, _lca), max_query(v, _lca)); + cout << _lca << " max: " << ans << "\n"; + + cin >> u >> v; + } + return 0; +} \ No newline at end of file diff --git a/2seals.cpp b/2seals.cpp new file mode 100644 index 0000000..819aceb --- /dev/null +++ b/2seals.cpp @@ -0,0 +1,58 @@ +#include +#include +using namespace std; + +struct Seal { + int x, y; + Seal(int a, int b): x(a), y(b) {} + int area() { + return x*y; + } +}; + +vector arr; +int n, a, b, ans; + +bool canFit(int i) { + return (max(arr[i].x, arr[i].y) <= max(a, b)); +} + +void cal(int i, int j, int a, int b) { + if ((arr[i].x + arr[j].x) <= a and max(arr[i].y, arr[j].y)<=b) { + ans = max(ans, arr[i].area()+arr[j].area()); + } + else if ((arr[i].x + arr[j].y) <= a and max(arr[i].y, arr[j].x)<=b) { + ans = max(ans, arr[i].area()+arr[j].area()); + } + else if ((arr[i].y + arr[j].x) <= a and max(arr[i].x, arr[j].y)<=b) { + ans = max(ans, arr[i].area()+arr[j].area()); + } + else if ((arr[i].y + arr[j].y) <= a and max(arr[i].x, arr[j].x)<=b) { + ans = max(ans, arr[i].area()+arr[j].area()); + } +} + +int main() { + int x, y, i=0; + cin >> n >> a >> b; + while (i++> x >> y; + arr.push_back(Seal(x, y)); + } + // sort(arr.begin(), arr.end(), [](Seal& x, Seal& y) { + // return x.area() > y.area(); + // }); + for (i=0; i)}2q<*bai@aL7$t;r9v6fN&c3#cP>-rvd>h*dGXnqgK@4Ue51X&F{EoKzIqi zMaGh_tUzBh($#ZH)64m7zFXuws`CjizRG!9R;=gIuAY-tS5HST3YPQh*ZhVw6T-`R z6!RxNxr_<4tb_X=+*gzXePBHqJ1E40zSIaxdIBA0T_K8P^@OaxGu`dIAuAk>{7Qbh zI+R}OQ(d}fJ~wbm9+q{gw@B@l@vA|7lFy^-5Ki(GF5-7<0RgnEkpI`oSEu=Tz%u!AnqRf9LwGSiER&K8deYn7-P=zU4Si(hA|I8Z=y7Ay4?D{1rYp8<_T!YH40<+_7aL9 zB(4YdTHJTX`XYCSy4vqPc_wrcI9+eTO>)$1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JXz81KiS@U#yDSb%9yG!R&`^k^#=p7Xb>Nb@RMpEI$<2UFP?MGO&H)Q-(MNiZi!{{4Np@TDi ze5WAwXK%za_iR0$)BKEogc7=*d;o z)J?DUPT%B-uZpjZS9<4M6pl6i12cBJE6(v+ibvjnfGpu7_$58z^%~D}c`<*4cL67U-ggTAVU5Q%{wa-z zb^P>iHJ;P>^MvE37&GysuLBTHv1YKevJLdo><@5&>_J4{E$k zIZDC;X0S+;g9Y^WR4}Zu;&5fbo#d_v-rX8ZUeoBdGDz;niHe3poBH zIFI^g1jkb@dWj-`f`7XVzfy+(lJPj6a@_*XQbh1t#+UNz%kYM>@<#>7Q?9nM{Jt_= zmEoT%!@nXpo^m}=hCfw?|6>{cY#Dwh*t``t{lDvG-1PYidRqf^;crmTf4sZ{H`Lpp z*CbF=gZ^!{9`|Pkt zC!xy7{z$}s#yW{35;6`oJ+OaY6V4p?YFVQd>h13HN3B!AP{beF76^xpLkA8NeSRzy MtlzPmgbxY*KZE9qHUIzs literal 0 HcmV?d00001 diff --git a/HLD/easy_to_code_subtree_queries.cpp b/HLD/easy_to_code_subtree_queries.cpp new file mode 100644 index 0000000..8423853 --- /dev/null +++ b/HLD/easy_to_code_subtree_queries.cpp @@ -0,0 +1,44 @@ +#include +using namespace std; +const int maxn = 1e5 + 5; +vector g[maxn]; +vector *vec[maxn]; +int cnt[maxn], sz[maxn], col[maxn]; + +int computeSubtreeSizes(int u, int p) { + for (int v: g[u]) { + if (v != p) { + sz[u] += computeSubtreeSizes(v, u); + } + } + sz[u]++; + return sz[u]; +} + + +void dfs(int v, int p, bool keep){ + int mx = -1, bigChild = -1; + for(auto u : g[v]) + if(u != p && sz[u] > mx) + mx = sz[u], bigChild = u; + for(auto u : g[v]) + if(u != p && u != bigChild) + dfs(u, v, 0); + if(bigChild != -1) + dfs(bigChild, v, 1), vec[v] = vec[bigChild]; + else + vec[v] = new vector (); + vec[v]->push_back(v); + cnt[ col[v] ]++; + for(auto u : g[v]) + if(u != p && u != bigChild) + for(auto x : *vec[u]){ + cnt[ col[x] ]++; + vec[v] -> push_back(x); + } + //now (*cnt[v])[c] is the number of vertices in subtree of vertex v that has color c. You can answer the queries easily. + // note that in this step *vec[v] contains all of the subtree of vertex v. + if(keep == 0) + for(auto u : *vec[v]) + cnt[ col[u] ]--; +} \ No newline at end of file diff --git a/HLD/lomsat_gelral.cpp b/HLD/lomsat_gelral.cpp new file mode 100644 index 0000000..cf1f4cd --- /dev/null +++ b/HLD/lomsat_gelral.cpp @@ -0,0 +1,57 @@ +#include +#define pb push_back +using namespace std; +const int maxn=1e5+12; +int n,col[maxn],sz[maxn],maxx,cnt[maxn]; +long long ans[maxn],can; +bool badboy[maxn]; +vectorg[maxn]; +void computeSubtreeSize(int v=0,int p=-1){ + sz[v]=1; + for(auto &u:g[v]) + if(u!=p)computeSubtreeSize(u,v),sz[v]+=sz[u]; +} + +void relax(int x){ + if(maxx<++cnt[x]) + maxx=cnt[x],can=x; + else if(maxx==cnt[x]) + can+=x; +} +void merge(int v,int p=-1){ + relax(col[v]); + for(auto &u:g[v]) + if(u!=p && !badboy[u]) + merge(u,v); +} +void remove(int v,int p=-1){ + cnt[col[v]]--; + for(auto &u:g[v]) + if(u!=p && !badboy[u]) + remove(u,v); +} +void dfs(int v=0,int p=-1,bool hrh=0){//HRH?! mipasandam! + int mx=0,big=-1; + for(auto &u:g[v]) + if(u!=p && sz[u]>mx) + mx=sz[u],big=u; + for(auto &u:g[v]) + if(u!=p && u!=big) + dfs(u,v,1); + if(big+1) + dfs(big,v),badboy[big]=1; + merge(v,p); + if(big+1) + badboy[big]=0; + ans[v]=can; + if(hrh) + remove(v,p),maxx=can=0; +} +int main(){ + scanf("%d",&n); + for_each(col,col+n,[](int &x){scanf("%d",&x);}); + for(int i=1,v,u;iVv0(uys_hDiJyX!E`nOxh3G1D)MY>oZ6auh z-}mi(?r3HtxxtCE%37MGd-vJ<{Oz;PKKtzRGox?+;>RytXjy^PmX%y(Sym;UnYEUc zPQC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wJJMW;+@vb)~XJyjrwD)eTf+U%U2865}V%rfW^xQIH1j4i(_G(L9P3JH`CQDxQ}mjy1h%c{6Q&VU4x= zWy~5QYkm!;+MlfrTk~rn+dClE;tA;4HOowA-&?bK&CEUMi7DJ=I*XW!7g;}9d%k-t zY&~58zIK7H85};ZdUf6HsS9A&dH{4d1_Tva`n)vxeJC?C08Xc9=%|=GP$a8s$woM7noT+RS_Cq7edaj z;ZDxgfuuET?wkC~;7M~&e*Aky0|xi+ z7p+Dn#{2h+wiw*MSJZ59|9;V7KYc{Y=XV~N-@iZf&j$DJ5p4tmjQ8&oIR^Ld6@ACx z{{5mi;IfwR^L8ztx88{R_l@}9`-uDZjy|*2q&N4E{tRtrynhdA8}51$pECE5`V8*h zNBR?k`}dG$1+RpZj64O$J}2&;p=s7?d>aLjVwKP96=#%u_LSitD8rAH;a@7lzfp!? ziEDx=yiopo%J7es;ZtS!#rVo&asC};_(Ns*{xbXnW%y7T{2?!dDh&y9HQ#KX&mxd+d^cy{86;JF`vwG|J4 z!U@;)EL`=IOS1O?{yMcMWbv%UUmcuxzpm8ZculKb*0m|-V)=DKu>;H;y09wWL0>eh zFQ3%R_RA+I_7{p$os)Z0l>glPoP`3;)0sk11+Un}Tqx_@SGo&jocBFk9_+n}rwOkm z=a9{R{pHhZERa`kt@au+{%f$g@fu3wW$XtPakKoSvCO8+%gS54eY23^oVVX_OJLDv zAubMJAF+JvpOw9mP5+|&XWQ;CN>w$ zGc=Bki$?^nXLYw6kOM|sB*fjRrB95_)jMM!_xC*#E!>UpZ%gse9=E0T)bNjI`vtoc z0ol6$-h0h)U^LOPzdcs9h!Wnin6z~ +using namespace std; + +int main() { + int n; + cin >> n; + map mp; + vector a(n), b(n); + for (int& x: a) { + cin >> x; + mp[x] = 1; + } + for (int& y: b) { + cin >> y; + mp[y] = 1; + } + int cnt = 0; + for (int i=0; i!ymQDMu8p(R(+dTniyWg)GI z-Nr$9eaT*3E@(Pz>IO1Zm`vlQ$)HRk*G;o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?KSMzOT-GhrQ%M#*udXNcH_Tk zd9@9nUFtX5f1hFTQ#APWRm+aMSfM)4DB}7kqev(}$SBfF_vl4xA>3Zu=6sHVg#qr&R|$scSp~5?Df05@mGubIe`

9x0Gt2~O}LW=Ch*k&i7PM-I}vj?6S;Ot>j6F+>yFL>4j c+4#V9*OmP7VRyV?7Nv1EWe%aGSPJF(A5h`Axc~qF literal 0 HcmV?d00001 diff --git a/bargaining_table.cpp b/bargaining_table.cpp new file mode 100644 index 0000000..85eed3d --- /dev/null +++ b/bargaining_table.cpp @@ -0,0 +1,36 @@ +#include +using namespace std; + +int main() { + int n, m; + cin >> n >> m; + int dp[n+1][m+1]; + for (int i=0; i<=m; i++) dp[0][i] = 0; + for (int i=0; i<=n; i++) dp[i][0] = 0; + string s; + for (int i=1; i<=n; i++) { + cin >> s; + for (int j=1; j<=m; j++) { + dp[i][j] = s[j-1]-'0'; + } + } + for (int i=1; i<=n; i++) { + for (int j=1; j<=m; j++) { + dp[i][j] += dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]; + } + } + int ans = 0; + for (int i=1; i<=n; i++) { + for (int j=1; j<=m; j++) { + for (int k=i; k<=n; k++) { + for (int l=j; l<=m; l++) { + int isOk = !(dp[k][l] - dp[k][j-1] - dp[i-1][l] + dp[i-1][j-1]); + if (isOk) { + ans = max(ans, 2*(k-i+1 + l-j+1)); + } + } + } + } + } + cout << ans << "\n"; +} \ No newline at end of file diff --git a/birds.cpp b/birds.cpp new file mode 100644 index 0000000..f022a65 --- /dev/null +++ b/birds.cpp @@ -0,0 +1,26 @@ +#include +#include +using namespace std; +const int mx = 1e4 + 2; +long long c[mx], cost[mx]; +long long X, W, B, n; +long long dp[mx/10 + 1][mx]; + +int main() { + cin >> n >> W >> B >> X; + for (int i=0; i> c[i]; + for (int i=0; i> cost[i]; + memset(dp, -1, sizeof(dp)); + dp[0][0] = W; + for (int i=0; i=0; k++) { + dp[i+1][j+k] = max(dp[i+1][j+k], min(dp[i][j]-k*cost[i]+X, W+(k+j)*B)); + } + } + } + int ans = 0; + for (int j=0; j=0) ans = j; + cout << ans << "\n"; + return 0; +} \ No newline at end of file diff --git a/colorfulPoints.cpp b/colorfulPoints.cpp new file mode 100644 index 0000000..5e9e6dd --- /dev/null +++ b/colorfulPoints.cpp @@ -0,0 +1,34 @@ +#include +using namespace std; +struct DS{ + int ch, count; +}; +const int mx = 1000003; +DS ds[mx]; +int ind; +string s; + +int main() { + cin >> s; + int n = s.length(); + for (int i=0; i 1) { + int left=0; + for (int i=1; i<=ind; i++) { + int x = ds[i].ch; + int y = ds[i].count-1-(i!=0 and i!=ind); + if (y<=0) continue; + if (x != ds[left].ch) ds[++left].ch = x; + ds[left].count = y; + } + ind = left; + ans++; + } + cout << ans << endl; + return 0; +} \ No newline at end of file diff --git a/convenient.cpp b/convenient.cpp new file mode 100644 index 0000000..f8af96c --- /dev/null +++ b/convenient.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +int main() { + int n; ios_base::sync_with_stdio( 0 ), cin.tie( 0 ), cout.tie( 0 ), cin >> n; + + auto next = [ n ] ( auto &x ) { if ( --x < 0 ) x += n; }; + + int a[ n ], s, f, t, u, v, sum = 0, max_sum = 0; + + for( int i = 0; i < n; i++ ) + cin >> a[ i ]; + + cin >> s >> f, u = s - 1, v = f - 2; + + for( int i = u; i <= v; i++ ) + sum += a[ i ]; + + for( int i = 1; i <= n; i++ ) + { + if ( sum > max_sum ) + max_sum = sum, t = i; + + sum -= a[ v ], next( u ), next( v ), sum += a[ u ]; + } + + cout << t << "\n"; + return 0; +} \ No newline at end of file diff --git a/demo.cpp b/demo.cpp new file mode 100644 index 0000000..84c4fa4 --- /dev/null +++ b/demo.cpp @@ -0,0 +1,9 @@ +#include +using namespace std; + +int main() { + int n; + cin >> n; + cout << n << "\n"; + return 0; +} \ No newline at end of file diff --git a/ehabAndMahmoudArray.cpp b/ehabAndMahmoudArray.cpp new file mode 100644 index 0000000..2664029 --- /dev/null +++ b/ehabAndMahmoudArray.cpp @@ -0,0 +1,40 @@ +#include + +using namespace std; +const int mx = 2e6 + 5; +vector mul[mx]; +bool prime[mx], erased[mx]; +int main() { + int n; + cin >> n; + set poss; + for (int i=2; i> in; + int out = *poss.begin(); + if (gt) { + out = *poss.lower_bound(in); + if (out != in) gt = false; + } + + cout << out << " "; + for (int u: mul[out]) { + for (int v=u; v +using namespace std; + +#define sd(a) scanf("%d",&a) +#define ss(a) scanf("%s",&a) +#define sl(a) scanf("%lld",&a) +#define clr(a) memset(a,0,sizeof(a)) +#define debug(a) printf("check%d\n",a) +#define F first +#define S second +#define MP make_pair +#define PB push_back +#define ll long long +#define INF 1000000000000000000 +vector digits; +ll p10[20]; +int main() +{ + // freopen("A1.in","r",stdin); + // freopen("A1.out","w",stdout); + int t,i; + p10[0] = 1; + for(i=1;i<18;i++) + p10[i] = p10[i-1]*10; + sd(t); + for(int tt=1;tt<=t;tt++) + { + ll n, n1,l = 0, r = 0; + digits.clear(); + sl(n); + n1 = n; + while(n>0) + { + digits.PB(n%10); + n/=10; + } + for(i=(int)digits.size()-1;i>=0;i--) + { + if(digits[i]&1) + break; + l += digits[i]*p10[i]; + r += digits[i]*p10[i]; + } + if(i>=0) + { + l += (digits[i]-1)*p10[i]; + r += (digits[i]+1)*p10[i]; + if(digits[i] == 9) r = INF; + i--; + for(;i>=0;i--) + l += 8*p10[i]; + } + ll ans = min(llabs(n1-l),llabs(n1-r)); + printf("Case #%d: %lld\n",tt,ans); + } +} diff --git a/fair_game.cpp b/fair_game.cpp new file mode 100644 index 0000000..56dafd9 --- /dev/null +++ b/fair_game.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; + +int main() { + int n; + cin >> n; + map mp; + for (int i=0; i> v; + mp[v]++; + } + // bool poss = true; + int cnt = 0, sum1=0, sum2=0; + vector first, sec; + for (auto x: mp) { + if (sum1 < sum2) sum1 += x.second, first.push_back(x.first); + else sum2 += x.second, sec.push_back(x.first); + cnt++; + } + if ((cnt>2 || cnt==1) || sum1!=sum2) { + cout << "NO\n"; + return 0; + } + cout << "YES\n"; + for (auto x: mp) { + cout << x.first << " "; + } + cout << "\n"; + return 0; +} \ No newline at end of file diff --git a/fair_nut.cpp b/fair_nut.cpp new file mode 100644 index 0000000..63225fa --- /dev/null +++ b/fair_nut.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include +using namespace std; + +struct edge { + int node, length; + edge(int _node = -1, int _length = -1) : node(_node), length(_length) {} +}; + +int N; +vector gas; +vector> adj; +long long best; + +long long dfs(int node, int parent) { + long long down = gas[node]; + + for (edge &e : adj[node]) + if (e.node != parent) { + long long child = dfs(e.node, node) - e.length; + best = max(best, down + child); + down = max(down, child + gas[node]); + } + + best = max(best, down); + return down; +} + +int main() { + scanf("%d", &N); + gas.resize(N); + adj.assign(N, {}); + + for (int &w : gas) + scanf("%d", &w); + + for (int i = 0; i < N - 1; i++) { + int u, v, c; + scanf("%d %d %d", &u, &v, &c); + u--; v--; + adj[u].emplace_back(v, c); + adj[v].emplace_back(u, c); + } + + best = 0; + dfs(0, -1); + printf("%lld\n", best); +} \ No newline at end of file diff --git a/fifa_fafa.cpp b/fifa_fafa.cpp new file mode 100644 index 0000000..a371391 --- /dev/null +++ b/fifa_fafa.cpp @@ -0,0 +1,164 @@ +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include т мом +// #include +// #include + +// #include +// #include + +// #define y0 sdkfaslhagaklsldk + +// #define y1 aasdfasdfasdf +// #define yn askfhwqriuperikldjk +// #define j1 assdgsdgasghsf +// #define tm sdfjahlfasfh +// #define lr asgasgash +// #define norm asdfasdgasdgsd +// #define have adsgagshdshfhds +// #define ends asdgahhfdsfshdshfd + +// #define eps 1e-8 +// #define M_PI 3.141592653589793 +// #define bsize 512 + +// #define ldouble long double +// using namespace std; + +// #define bs 1000000007 + +// const int N = 400031; + +// long double R,x1,y1,x2,y2; + +// long double get_dist(long double x,long double y){ +// return sqrt(x*x+y*y); +// } + +// bool outside(){ +// return get_dist(x2,y2)>R; +// } + +// void show_answer(long double x,long double y,long double r){ +// x+=x1; +// y+=y1; +// cout.precision(20); +// cout<>R>>x1>>y1>>x2>>y2; +// x2-=x1; +// y2-=y1; +// if (outside()){ +// show_answer(0,0,R); +// } +// else +// { +// long double D=get_dist(x2,y2); +// long double dir=atan2(y2,x2); +// dir=dir+M_PI; +// long double diam=R+D; +// long double rad=diam/2; +// rad-=D; +// long double ax=rad*cos(dir); +// long double ay=rad*sin(dir); +// //cout.precision(20); +// show_answer(ax,ay,rad+D); +// } +// // cin.get(); cin.get(); +// return 0; +// } + +#include +#define f first +#define s second +using namespace std; +const double eps = 1e-9; +double x1, x2, Y1, y2, x, y, R; +typedef pair point; + +struct Circle { + point center; + double radius; + Circle(point p, double r): center(p), radius(r) {} +}; + +struct Line { + double m, c; + Line(double m_, double c_): m(m_), c(c_){} + + double getYCorrespoindingTo(double x) { + return m*x + c; + } +}; + +struct LineCircleInterSection { + point p1, p2, p; + double a, b, c; + LineCircleInterSection(Line l, Circle cr) { + a = 1 + 1.0f * pow(l.m, 2); + b = 2.0f * (cr.center.f - l.m*l.c + l.m*cr.center.s); + c = pow(cr.center.f, 2) + pow(cr.center.s, 2) + pow(l.c, 2) - l.c * cr.center.s - pow(cr.radius, 2); + double disc = pow(b, 2) - 4 * a * c; + double x1 = 1.0f * (b + sqrt(disc)) / (2 * a); + double x2 = 1.0f * (b - sqrt(disc)) / (2 * a); + p1 = point(x1, l.getYCorrespoindingTo(x1)); + p2 = point(x2, l.getYCorrespoindingTo(x2)); + } + + double dist(point p11, point p22) { + return sqrt(pow(p11.f-p22.f, 2) + pow(p11.s-p22.s, 2)); + } + void print(point x) { + cout << "[" << x.f << ", " << x.s << "]\n"; + } + point getCenter(point p_) { + print(point((p_.f+p2.f) / 2, (p_.s+p2.s) / 2)); + print(point((p_.f+p1.f) / 2, (p_.s+p1.s) / 2)); + if (dist(p_, p1)+eps < dist(p_, p2)) { + return point((p_.f+p2.f) / 2, (p_.s+p2.s) / 2); + } + return point((p_.f+p1.f) / 2, (p_.s+p1.s) / 2); + } +}; + +int main() { + cin >> R >> x1 >> Y1 >> x2 >> y2; + auto dist = [&]()->double { + return 1.0f * sqrt(pow(x1-x2, 2)+pow(Y1-y2, 2)); + }; + cout.precision(20); + if(dist() < eps) { + cout << (x1 + R/2) << " " << Y1 << " " << R/2 << "\n"; + } + else if (dist() < R) { + double m = 1.0f * (y2-Y1) / (x2-x1); + double c = Y1 - m*x1; + Line l(m, c); + Circle cr(point(x1, Y1), R); + LineCircleInterSection ds(l, cr); + point p = ds.getCenter(point(x2, y2)); + double r = (R + dist()) /2; + cout << p.f << " " << p.s << " " << r << "\n"; + } else { + cout << x1 << " " << Y1 << " " << R << "\n"; + } + return 0; +} \ No newline at end of file diff --git a/gen.cpp b/gen.cpp new file mode 100644 index 0000000..97f1ce4 --- /dev/null +++ b/gen.cpp @@ -0,0 +1,24 @@ +#include +#include +using namespace std; +int get(char* s) { + int n = strlen(s); + int out = 0; + for (int i=0; i +const double EPS = 1e-9; + +double DEG_to_RAD(double x) +{ + return x * M_PI / 180; +} + +struct point +{ + double x, y; + point() { x = y = 0.0; } + point(double _x, double _y) : x(_x), y(_y) {} + + bool operator<(point other) const + { // override less than operator + if (fabs(x - other.x) > EPS) + return x < other.x; + return y < other.y; + } + + bool operator==(point other) const + { + return (fabs(x - other.x) < EPS && (fabs(y - other.y) < EPS)); + } + + double distTo(point p2) + { // Euclidean distance // hypot(dx, dy) returns sqrt(dx * dx + dy * dy) + return hypot(x - p2.x, y - p2.y); + } + + point rotate(point p, double theta) + { + double rad = DEG_to_RAD(theta); // multiply theta with PI / 180.0 + return point(p.x * cos(rad) - p.y * sin(rad), p.x * sin(rad) + p.y * cos(rad)); + } +}; +// useful for sorting // first criteria , by x-coordinate // second criteria, by y-coordinate + +struct line +{ + double a, b, c; + + void pointsToLine(point p1, point p2, line &l) + { + if (fabs(p1.x - p2.x) < EPS) + { // vertical line is fine + l.a = 1.0; + l.b = 0.0; + l.c = -p1.x; + } + else + { + // default values + l.a = -(double)(p1.y - p2.y) / (p1.x - p2.x); + l.b = 1.0; // IMPORTANT: we fix the value of b to 1.0 l.c = -(double)(l.a * p1.x) - p1.y; + } + } + + bool areParallel(line l1, line l2) + { // check coefficients a & b + return (fabs(l1.a - l2.a) < EPS) && (fabs(l1.b - l2.b) < EPS); + } + bool areSame(line l1, line l2) + { // also check coefficient c + return areParallel(l1, l2) && (fabs(l1.c - l2.c) < EPS); + } + bool areIntersect(line l1, line l2, point &p) + { + if (areParallel(l1, l2)) + return false; // no intersection // solve system of 2 linear algebraic equations with 2 unknowns + p.x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b); + // special case: test for vertical line to avoid division by zero + if (fabs(l1.b) > EPS) + p.y = -(l1.a * p.x + l1.c); + else + p.y = -(l2.a * p.x + l2.c); + return true; + } +}; + +struct vec +{ + double x, y; // name: ‘vec’ is different from STL vector + vec(double _x, double _y) : x(_x), y(_y) {} + vec toVec(point a, point b) + { // convert 2 points to vector a->b + return vec(b.x - a.x, b.y - a.y); + } + vec scale(vec v, double s) + { + return vec(v.x * s, v.y * s); + } + // nonnegative s = [<1 .. 1 .. >1] // shorter.same.longer + point translate(point p, vec v) + { + return point(p.x + v.x, p.y + v.y); // translate p according to vF + } + + double dot(vec a, vec b) { + return (a.x * b.x + a.y * b.y); + } + + double magnitudeOf(vec v) { + return v.x * v.x + v.y * v.y; + } + + // returns the distance from p to the line defined by + // two points a and b (a and b must be different) + // the closest point is stored in the 4th parameter (byref) + double distToLine(point p, point a, point b, point &c) + { + // formula: c = a + u * ab + vec ap = toVec(a, p), ab = toVec(a, b); + double u = dot(ap, ab) / magnitudeOf(ab); + c = translate(a, scale(ab, u)); // translate a to c + return p.distTo(c); // Euclidean distance between p and c + } +}; \ No newline at end of file diff --git a/guessTheNumber.cpp b/guessTheNumber.cpp new file mode 100644 index 0000000..7b65bcc --- /dev/null +++ b/guessTheNumber.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +int main(){ + string op; + int l = 1, r = (int)1e6; + while(1) { + int mid = (l+r) >> 1; + cout << mid << "\n"; + fflush(stdout); + cin >> op; cin.ignore(); + if (l>r) { + cout << "! " << r << "\n"; + break; + } + if (op == "<") { + r = mid-1; + } else { + l = mid+1; + } + } + fflush(stdout); + return 0; +} \ No newline at end of file diff --git a/indent b/indent new file mode 100755 index 0000000000000000000000000000000000000000..e9554d95a7e9399ae65b3b67042979cdf9a83ba6 GIT binary patch literal 16688 zcmeHOeNbH2b-xRuMzQQgO4=x?WUn2`mMm9d^<_!OF|v5c!v+Nj(GoT4V_6nh7Zwb= zHge4r1-HQzN$r5P?^8sbn>=&T1u>Gd1_Kzzeyw)@To&%{n@bZ4hi(Guh+k99 zh7k>QMHK>&EwAWyOa}CefRqSdB&)JqBziJY!|060>O0e94_v5C{*%h z^&@#kbEu^~)B&b!c`vM#^1iMF5KeYar+NA{1%pPYD;R2z8qq*~w!DTrq`V@v2!zj( zmliB5h7s(Hc7!8Mik>YmdZ(1<${;*5xpbFi7_rEc;YfoKjx@G`m@ThM$&0HFglEfe zWf3GliDNE?QMPOUu8bC+)JwEqA$Jf0I45#gB=QsZaC)r`Bhq4Y9%`*`YcblR9oLkn zy0bj$?EE9zCq zl*j=n(-!|AGVxz4)$R~t=K_t?*N40Wc|)wTV?#^0enZ2dmImOIXzfYvn;)GXe(g`T ztp8Hw4^DjZ;L~4)y4;WFc>4#S#0Pl3yf#bz*mED+i;&&42Gb=u?OvB6A&m6z69`UKalTkl^FrNZ^B=e7*~g7LSpd~^A$4|PUEt?M6FUBE5GJ;q(swO%OrIw=969um<0|-`5>*24h*@LQQ9N6XFo$(p(kyYRW%h3f{ z><`7Qnyabv;IX@>ZS8Wel$j zvCGz&^B|b>wJ9*BHqAC+_|qP1%=)^sGTolp>lRS$%Bi)dt;(sx-BY)m|6Gap89H&= z+SG3m26?^RQ!s@h7APX-@-H~}qOTsT!Hh4+8BYMaY%NJzl~--;s@{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ck~%mS9_?GmKzmbcCYK z9c@p_H635L|CV4&DA1ujM#h?yEY;EN*ypX`NFW+wS9O?f1iJ!8eW)oMG2nv1X6i9D z+Y+LYUHY^Ko2WI^3eAYECl4rm8!-l`N*)7GnF|cDvNaHnh)*@Ni<9{QaXLRD#`8s9 zYcswb3I$`)5I#u?Q0U!qKy1e|a6EbTHzJlkqGG3!gG zWct>O{t`y#P^V9+md!iJUXOKdD7g-2c3`?TtBP;eX2^_tvs}NT_&Ynm4PP#1 zMcmW{%P{6&CXIkFa4j|Xs%k{Ax^vI6H1vBo#b&UjPbRbH*IE5<`s8}EqWCnGA>@V* ztM9kJJf+U>^}dd$H`x6e6Tbe?d?1}2P~Ird;_4oGmN54Yd6u4egq@|PJ!GM?>jG@= z?a;bF$Mk6xZF7&Q2EHTCI-e@i?7?!?*y4Sf2>!v@?hFMJE9X>@zKT`g68tkDQV9N*8mcgS>Ki`&uaZS9lP% bx=a1!?%f&R)VG8-&ZBIfNAde{SrPvWvu>|5 literal 0 HcmV?d00001 diff --git a/input.in b/input.in new file mode 100644 index 0000000..fe990aa --- /dev/null +++ b/input.in @@ -0,0 +1,2001 @@ +2000 +s +f +f +f +f +f +s +s +s +f +f +s +s +f +s +s +s +f +f +f +f +f +s +s +f +s +f +s +f +s +s +s +s +f +s +s +s +s +f +s +f +s +f +s +f +f +f +f +s +f +f +f +f +s +f +f +f +s +s +s +s +s +s +f +s +f +f +f +f +f +f +f +s +f +f +s +s +f +f +s +f +f +f +f +f +s +s +s +f +f +s +s +f +f +s +s +f +s +s +s +f +f +f +s +s +f +f +f +f +s +s +f +f +s +s +f +f +s +s +s +f +f +s +f +s +f +f +f +f +f +f +f +f +f +f +s +f +s +s +s +f +f +s +s +s +f +s +f +f +f +f +s +s +s +s +f +f +f +s +s +f +f +f +s +f +f +s +f +s +s +f +f +f +f +f +s +f +s +s +f +f +s +f +f +f +s +s +f +f +f +f +s +f +f +s +s +f +f +s +s +f +f +f +s +f +s +s +s +s +s +f +s +f +f +s +f +s +f +s +s +s +s +f +f +s +f +s +f +f +s +f +f +s +f +f +f +s +f +s +f +f +f +s +s +f +f +s +s +f +s +s +s +f +s +f +s +f +f +s +f +f +s +s +f +f +s +s +s +f +s +s +f +f +f +f +f +s +f +s +f +s +s +f +f +f +f +f +s +f +f +f +f +s +f +s +s +f +s +s +f +f +f +s +s +f +s +s +s +s +s +s +f +f +s +s +s +f +s +f +f +f +f +f +s +s +s +s +f +s +f +f +f +s +f +f +f +s +s +s +f +f +f +s +s +s +s +f +f +f +f +s +f +s +s +s +s +f +f +s +f +f +s +s +s +f +s +s +s +f +f +f +f +s +s +f +f +f +f +s +s +f +f +f +f +f +s +s +s +f +f +f +s +f +s +s +s +f +f +f +s +f +s +s +f +f +s +f +f +f +s +f +f +s +f +s +s +f +s +s +s +s +s +s +s +s +f +s +s +s +f +s +s +f +f +s +s +s +s +s +f +s +f +s +f +f +f +s +f +s +s +s +f +f +f +s +s +f +f +s +s +s +f +f +s +f +s +f +s +s +f +f +s +s +s +s +f +f +f +f +f +f +f +s +s +f +s +f +s +s +s +f +f +s +s +s +f +f +s +f +s +f +s +s +s +f +s +s +f +f +f +f +s +f +f +f +s +f +f +f +f +s +f +f +s +f +s +s +f +s +f +f +s +s +s +s +s +f +s +f +f +s +s +f +f +f +s +f +s +f +f +f +f +s +f +f +s +s +f +s +f +f +s +s +s +f +f +f +f +s +s +f +f +f +f +s +f +s +s +s +f +s +f +f +s +s +s +s +s +f +s +s +f +s +s +s +f +f +s +f +f +f +s +s +s +f +f +s +f +f +s +f +f +f +s +s +f +f +s +f +f +s +f +s +s +s +s +f +s +f +f +s +s +f +s +s +s +s +s +s +s +s +f +s +f +f +s +f +f +f +s +f +f +s +f +f +s +s +f +f +f +f +f +f +s +s +f +s +f +s +f +s +f +f +s +s +s +s +f +f +s +s +f +f +f +s +f +s +s +s +f +f +s +s +s +s +s +f +s +s +f +s +s +f +s +f +f +s +f +f +f +f +f +f +s +s +s +f +f +f +s +f +f +f +f +f +f +f +f +f +s +f +f +f +s +f +s +s +f +s +f +s +s +f +f +s +s +s +f +f +s +s +s +f +s +f +f +f +f +s +f +f +s +s +f +f +s +s +f +f +f +f +s +s +s +f +f +s +f +f +f +f +s +s +f +f +s +f +s +f +s +s +f +f +f +f +s +f +f +f +s +s +s +f +s +f +s +f +f +f +f +s +f +f +f +s +s +s +s +s +f +s +s +s +s +f +f +s +s +f +f +f +s +s +s +f +s +s +s +f +s +s +f +s +s +f +s +s +f +f +f +f +f +s +f +f +f +s +f +f +s +f +s +f +s +s +s +f +s +f +s +s +s +s +f +f +f +s +s +f +f +f +f +s +f +s +s +s +f +s +s +f +f +f +s +f +f +s +f +s +f +s +s +s +f +f +s +s +f +s +s +s +s +f +s +f +s +f +f +s +f +s +s +f +s +f +s +s +s +f +s +f +f +f +s +s +s +s +s +f +s +s +f +s +f +s +s +s +s +f +f +s +s +s +s +s +f +f +f +s +f +f +s +s +s +s +f +f +s +s +f +f +s +s +f +f +s +f +f +s +f +s +s +s +s +s +f +s +s +f +s +f +s +f +s +s +s +f +f +s +f +s +s +f +s +f +s +s +f +f +s +f +s +s +f +f +s +s +f +f +f +f +f +f +f +f +s +s +s +s +f +f +f +f +s +s +f +s +s +s +s +f +f +f +s +f +f +s +f +s +s +f +f +s +f +f +f +s +s +s +s +s +f +f +s +s +f +s +f +s +s +f +f +f +f +f +s +s +s +s +f +s +f +s +f +f +s +s +s +s +f +s +s +f +f +f +f +f +s +f +f +s +f +s +s +s +f +f +s +s +s +f +s +f +f +s +f +f +f +s +f +f +s +f +f +s +s +s +f +s +s +f +s +s +f +f +s +f +s +s +f +s +s +s +f +s +f +f +s +s +s +f +s +s +s +f +s +f +f +f +f +s +s +s +s +f +s +f +s +s +s +f +s +s +f +s +f +f +f +s +s +f +s +f +s +s +s +s +s +s +s +s +s +s +f +s +s +s +s +f +f +f +f +s +s +s +s +f +s +s +s +s +s +f +f +s +s +f +f +s +s +s +s +f +s +s +s +f +f +s +f +s +s +f +s +f +s +s +s +s +s +s +s +f +f +f +s +f +s +f +f +f +f +s +s +f +s +f +s +f +f +s +s +f +f +s +f +f +f +s +s +f +s +f +s +s +s +f +s +s +f +s +f +s +f +f +f +f +f +f +f +f +s +f +f +f +s +f +f +s +s +s +f +f +s +s +s +s +f +f +f +s +f +f +f +s +f +f +f +s +s +f +s +f +s +f +s +f +s +f +f +s +f +s +s +f +s +s +f +f +s +s +s +f +s +s +s +f +s +f +s +f +s +f +f +s +s +s +f +f +f +f +s +f +f +s +f +f +s +s +s +s +s +s +f +f +f +f +f +s +f +f +f +s +s +f +f +f +f +s +s +f +f +f +f +s +f +s +f +s +f +s +f +s +s +s +s +s +f +f +f +s +s +s +f +f +f +f +f +f +s +s +s +f +f +s +s +s +f +s +s +f +s +f +s +f +s +s +f +s +f +s +f +s +f +s +f +f +s +f +s +s +s +s +f +s +s +s +s +s +f +s +f +f +f +f +s +s +s +f +s +f +s +f +f +s +f +f +s +f +s +f +f +s +s +s +f +s +s +s +f +f +s +f +s +f +f +f +f +s +s +s +s +s +f +s +s +s +s +f +f +s +s +s +f +s +f +f +f +s +s +f +f +s +f +s +f +s +s +f +f +s +s +f +s +s +s +s +s +f +f +f +s +f +s +f +f +f +s +f +s +s +s +f +f +f +f +f +s +f +s +s +f +f +s +f +f +s +f +s +s +s +f +s +f +s +f +f +f +s +f +f +f +s +f +f +s +s +f +f +s +s +s +f +s +s +s +f +s +f +f +f +s +s +f +f +s +s +s +f +s +s +f +s +s +s +f +s +s +s +f +s +f +s +f +s +s +f +s +f +f +s +s +s +f +s +f +f +f +f +s +f +f +f +f +f +f +f +s +f +f +s +f +s +f +s +s +f +s +f +f +f +s +s +s +s +f +f +s +s +f +f +f +f +f +s +s +s +s +s +s +f +f +f +f +f +s +f +s +f +f +f +f +s +f +s +f +s +f +s +f +s +f +f +s +s +f +f +s +s +s +s +s +f +s +f +s +f +s +f +s +f +s +f +f +f +s +s +f +f +f +s +s +s +f +f +s +f +f +f +s +f +s +s +f +f +s +s +f +s +s +f +f +s +s +f +f +s +s +s +s +f +s +s +f +f +f +f +f +f +s +f +f +f +s +f +s +f +f +f +s +f +f +s +s +s +s +f +s +s +s +s +s +s +s +s +s +s +s +s +f +s +f +f +s +f +s +s +s +s +s +s +f +s +f +f +f +s +s +s +f +f +s +f +f +f +f +s +s +s +f +s +s +f +f +f +f +f +f +f +f +s +s +f +s +s +f +s +f +f +s +s +s +f +s +f +f +f +f +f +f +f +f +f +f +s +f +f +f +f +s +s +s +s +s +f +s +s +s +s +f +f +f +f +f +f +s +f +f +s +f +s +f +s +s +f +s +s +s +s +f +s +f +s +f +f +s +s +f +s +f +f +s +s +s +f +f +s +s +f +s +s +f +s +f +s +s +f +s +s +s +f +s +s +f +f +s +f +s +s +s +s +f +f +f +f +s +s +s +s +f +f +f +s +f +s +f +s +f +f +f +s +f +s +f +s +f +s +f +f +f +f +f +s +f +f +s +s +f +f +s +f +f +s +s +s +s +s +f +s +s +f +f +s +s +f +f +f +s +s +f diff --git a/laser.cpp b/laser.cpp new file mode 100644 index 0000000..1a4f66a --- /dev/null +++ b/laser.cpp @@ -0,0 +1,36 @@ +#include +using namespace std; +using ll = long long; +int main() { + ll n, u; + cin >> n >> u; + ll E[n]; + for (int i=0; i> E[i]; + } + + ll i=0, j = 1; + long double eff = 0, eps = 1e-9; + while (i < n) { + while (j= 3) { + // cout << i << " " << j << " " << E[j]-E[i]; + if (E[j]-E[i] <= u) { + long double tmp = 1.0f * (E[j]-E[i+1]) / (E[j]-E[i]); + if (eps + eff < tmp ) eff = tmp; + } + if (E[j-1]-E[i] <= u and (j-i)>=3) { + long double tmp = 1.0f * (E[j-1]-E[i+1]) / (E[j-1]-E[i]); + if (eps + eff < tmp ) eff = tmp; + } + // cout << " " << eff << "\n"; + } + i++; + } + if (eff == 0.0f) eff = -1.0; + printf("%.12Lf\n", eff); + return 0; +} \ No newline at end of file diff --git a/lecture_sleep.cpp b/lecture_sleep.cpp new file mode 100644 index 0000000..10b1853 --- /dev/null +++ b/lecture_sleep.cpp @@ -0,0 +1,34 @@ +#include +using namespace std; + +int main() { + ios::sync_with_stdio(false); + cin.tie(0); + int n, k; + cin >> n >> k; + long a[n+1], a_[n+1]; + int t[n]; + a[0] = a_[0] = 0; + for (int i=0; i> a[i+1]; + a[i+1] += a[i]; + a_[i+1] = 0; + } + long ans = 0; + for (int i=0; i> t[i]; + // t[i+1] += t[i]; + if (t[i]) ans += (a[i+1]-a[i]); + else a_[i+1] += (a[i+1]-a[i]); + a_[i+1] += a_[i]; + // cout << a_[i+1] << " \n"[i==n-1]; + } + // cout << ans << "\n"; + long total = ans; + for (int i=1; i<=n-k+1; i++) { + ans = max(ans, total + a_[i+k-1] - a_[i-1]); + // cout << i << " : " << ans << "\n"; + } + cout << ans << "\n"; + return 0; +} \ No newline at end of file diff --git a/lids.cpp b/lids.cpp new file mode 100644 index 0000000..89f84fd --- /dev/null +++ b/lids.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +using namespace std; + +int dp[2][2][11][10][10], mx, k; +vector num1, num2, num; +int f(int eq, int nz, int curL, int last, int ind, int n) { + if (ind == num.size()) { + if (curL == k && nz==1) return 1; + return 0; + } + if (dp[eq][nz][curL][last][ind] != -1) return dp[eq][nz][curL][last][ind]; + int lmt = 9; + if (eq == 0) { + lmt = num[ind]; + } + int ans = 0; + for (int i=0; i<=lmt; i++) { + int neq = eq; + int n_curL = curL; + int nLast = last; + int nnz = nz; + int nn = n*10 + i; + if (i>0) nnz = 1; + if (i < num[ind] || eq) neq = 1; + //ignoring the current digit + ans += f(neq, nnz, n_curL, nLast, ind+1, nn); + if (i > last) { + nLast = i; + ans += f(neq, nnz, n_curL+1, nLast, ind+1, nn); + } + } + (dp[eq][nz][curL][last][ind]=ans); + return ans; +} + +vector getNum(int a) { + vector ans; + while (a > 0) { + ans.push_back(a%10); + a /= 10; + } + reverse(ans.begin(), ans.end()); + return ans; +} + +void solve(int a, int b) { + if (a > b) swap(a, b); + num1 = getNum(a-1); + num2 = getNum(b); + vector temp; + while (temp.size()+num1.size() < num2.size()) temp.push_back(0); + for_each(num1.begin(), num1.end(), [&](int x) { + temp.push_back(x); + }); + num1 = temp; + // cout << num1.size() << num2.size() << endl; + for (k=1; k<=min(9, (int)num2.size()); k++) { + memset(dp, -1, sizeof(dp)); + int ans = 0; + num = num2; + // for (int i=0; i<=num[0]; i++) { + ans += f(0, 0, 0, 0, 0, 0); + // } + num = num1; + memset(dp, -1, sizeof(dp)); + // for (int i=0; i<=num[0]; i++) { + ans -= f(0, 0, 0, 0, 0, 0); + // } + cout << k << " " << ans << endl; + } +} + +int main() { + int a, b; + cin >> a >> b; + solve(a, b); + return 0; +} \ No newline at end of file diff --git a/lucky-dip.cpp b/lucky-dip.cpp new file mode 100644 index 0000000..a2bab63 --- /dev/null +++ b/lucky-dip.cpp @@ -0,0 +1,51 @@ +#include +using namespace std; + +#define LL long long + +#define maxn 20100 +#define INF 0x33333333 + +int v[maxn]; + +int main() +{ + freopen("B-small-practice.in", "r", stdin); + int t, cas = 0; + scanf("%d", &t); + while(t--){ + cas++; + int n, k; + scanf("%d %d", &n, &k); + for(int i = 0; i < n; i++){ + scanf("%d", &v[i]); + } + sort(v, v + n); + double ans = 0; + + auto f = [](double a, double b){return a + b;}; + double s = accumulate(v, v + n, 0.0, f); + double mid = (n & 1) ? v[n / 2]: (v[n / 2] + v[n / 2 - 1]) / 2; + double av = s * 1.0 / n; + if(k == 0){ + ans = av; + }else{ + double prev = av; + for(int draw = 1; draw <= k; draw++){ + double cur = 0.0; + for(int i = 0; i < n; i++){ + if(v[i] <= prev){ + cur += prev; + }else{ + cur += v[i]; + } + } + cur /= n; + prev = cur; + } + ans = prev; + } + printf("Case #%d: %.6f\n", cas, ans); + } + return 0; +} \ No newline at end of file diff --git a/magicNums.cpp b/magicNums.cpp new file mode 100644 index 0000000..b6b6950 --- /dev/null +++ b/magicNums.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +using namespace std; +int m, d; +char a[2007], b[2007]; +int len; +int dp[2007][2007][2][2]; +const int MOD = 1e9 + 7; +int dfs(int p, int r, int x, int y) { + // cout << p << " " << r << " " << x << " " << y << endl; + if (p == len) return r == 0; + int &ret = dp[p][r][x][y]; + if (ret != -1) return ret; + ret = 0; + int L = x == 1 ? a[p] - '0' : 0; + int R = y == 1 ? b[p] - '0' : 9; + for (int i = L; i <= R; ++ i) { + if ((p & 1) && i != d) continue; + if (!(p & 1) && i == d) continue; + ret += dfs(p + 1, (r * 10 + i) % m, x && i == L, y && i == R); + if (ret >= MOD) ret -= MOD; + } + return ret % MOD; +} +int main() { + scanf("%d%d%s%s", &m, &d, a, b); + len = strlen(a); + memset(dp, -1, sizeof(dp)); + printf("%d\n", dfs(0, 0, 1, 1)); +} \ No newline at end of file diff --git a/milking_order.cpp b/milking_order.cpp new file mode 100644 index 0000000..4e2aee7 --- /dev/null +++ b/milking_order.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +using namespace std; + +vector suc[100002]; +int n; +int pred[100002], result[100002]; +vector > edge[50004]; + +bool can(int k) { + for (int i=0; i q; + for (int i=0; i> n >> m; + for (int i = 0; i < m; i++) { + int d; + cin >> d; + int last; + for (int j = 0; j < d; j++) { + int e; + cin >> e; + e--; + if (j > 0) { + edge[i].push_back(make_pair(last, e)); + } + last = e; + } + } + + // Binary search + // Invariant: lo <= ans < hi + int lo = 0; + int hi = m+1; + while (hi > lo+1) { + int mid = (lo + hi) / 2; + if (can(mid)) { + lo = mid; + } else { + hi = mid; + } + } + + int ans = lo; + + // Run this again, to get the answer + // into the `result` array. + can(ans); + + for (int i = 0; i < n; i++) { + cout << result[i]+1 << " \n"[i==n-1]; + } + return 0; +} diff --git a/mountains.cpp b/mountains.cpp new file mode 100644 index 0000000..9c3cf94 --- /dev/null +++ b/mountains.cpp @@ -0,0 +1,35 @@ +#include +#include +using namespace std; +struct point{ + int x, y; + point(): x(0), y(0) {} + int diff() const { + return x-y; + } + int plus() const { + return x+y; + } + bool operator<(const point& other) const { + return (other.diff() == diff()) ? (plus() > other.plus()) : (diff()> n; + point peaks[n]; + for (int i=0; i> peaks[i].x >> peaks[i].y; + } + sort(peaks, peaks+n); + int mx = -1234, ans=0; + for (int i=0; i= mx) ans++, mx = peaks[i].plus(); + } + cout << ans << "\n"; + return 0; +} \ No newline at end of file diff --git a/mst b/mst new file mode 100755 index 0000000000000000000000000000000000000000..f9a7309670855c043596697008fcac1f614be4eb GIT binary patch literal 26804 zcmeHwe|%ikb>|yP0-0YUTtmHq1_1`_Lcp?(BM=4|H1M=YL|}_`D0D23$CipDEBayN z5;fzDhwA$AvPzdp-3Ah6Ki#d`l3kHy5^dulBjXQJ{P6}666%s|qPB#Lx=yRI`G7*Q z@qWMO+$W93CLxf1KKaA%8lXBA!$jc$o--Lkld)URDkb1aUw zIc2!fB)Ou|-gtknMF5KVO`n6#fPQzCmLXocP@G7j5RFEAdi%Eb%#(`wU3ZJ}J7!A+ zcu=9-@>^&h`9)jf?OpM16e{L7XZcAZkx!iCK7XCkzFo0cG~OSJclAblTehFVZ=<&F zJUa<)a7->)g2;1&jG@ zvHbqbG9g~fqmV!4z?K~j0u%2NdvNy-UxC@Z|8(a!d0&)$yh zyW68(z1{D~kMb^8t=6}g$lDbG0vL_%+Fc-ar|_#leNI8OtwY?lR49~>l{Swc8f|a+ zdF^v+m0yLOSK@{I*xze$2Uj%Ov73|7)*Ic~*BLvdeOob>WL0h}5HIAnG+<;QUYL`_ z8fKv!`%=#GC{TW{;|xNuhBiCS6q>Z{Kd3?j$sw!q2OOsk@Z(X;5juM=()LxN^D2NZ z!_7J8{Z5zryN=U%n#>D8tHgaC?i>1gx^HN2+kV52z3n@I^ST5#+wreEt~pTqosCDH z{#whISG|7q_O+l@;+8&M0A+=nX&Ke?{v`C_E+}6%`5LBgarw=AdwSy?*WYfdptR#$jhpS6{wVZ0 z;A)F=e9v5GM&Qf{oEd>%rx9p&&G+5pi3-;Y%(>pcT>h)e;m{_JR6O*2_%av-$=`Qk z6w1=|%l_c=A%OGm+Tb`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pNFl%%^%a-fSVsD{JONY(uu+azy@KRwdG8zIY(-d!3TcN`!VLM zuUtEy>n4(_TITbq2XL8^>5?}EWF^|oBv;Ep5F`8_hHZ%UiY3oE&TBNDZXQL zmxJ9Ooy=$lU7Tn~zk_XeH)L(`&XVtcKYPl8`af?sSx{_#8?dmC)Iq2^%?{G$oEnnS zj9MBd`vBnYPo(U5v-+!0iX)c`We7;G^0o3O&&VUVL+Pm2}qIW1{n zvuO!MyG%>f?In=Y#4&^2CLy<(!T$1;h$b3sRs6fwhee|B?(40^4u9c&Ral4x;iz96 zH?7n9(O7#+=PvBV+uQNKy4d}HAzx_Lu9h7VVnCD+LCw?0j3hW)b(57~gaD&$V8^fc z=EIl_*&+6~xtjkN@0=I82*`!+ERGtY>_QNjH4DO18U;o;r=w%@jqj67(Ogu$hjy&} zm9!(68-&z%weQ~E(jMJ|z$!y +#include +using namespace std; + +int bit[100005], n; +pair a[100005]; + +void update(int x) { + for (; x0; ) { ans += bit[x]; x -= (x & -x); } + return ans; +} + +int main() { + ifstream cin("sort.in"); + ofstream cout("sort.out"); + cin >> n; + for (int i=1; i<=n; i++) { + cin >> a[i].first; + a[i].second = i; + } + auto amax = [&](int& f, int s) -> void { if (f < s) f = s; }; + sort(a+1, a+1+n); + int ans = 1; + for (int i=1; i +using namespace std; + +int main() { + int n; + cin >> n; + string s; + cin >> s; + set st; + int ans = 0; + for (int i=0; i='A' and s[i]<='Z') { + ans = max(ans, (int)st.size()); + st.clear(); + } else { + st.insert(s[i]); + } + } + if (st.size() > 0) ans = max(ans, (int)st.size()); + cout << ans << endl; + return 0; +} \ No newline at end of file diff --git a/python_indentation.cpp b/python_indentation.cpp new file mode 100644 index 0000000..2b06709 --- /dev/null +++ b/python_indentation.cpp @@ -0,0 +1,49 @@ +#include +#include +using namespace std; +const int mx = 5 * 1e3 + 2; +const int mod = 1e9 + 7; +int dp[mx][mx]; +int a[mx], n; +int f(int pos, int nest) { + if(nest < 0){ + return 0; + } + if(pos > n){ + return 1; + } + if(dp[pos][nest] != -1){ + return dp[pos][nest]; + } + int res = f(pos , nest - 1); + if(a[pos-1] == 0){ + res += f(pos + 1 , nest); + } + else{ + res += f(pos + 1 , nest + 1); + res -= f(pos + 1 , nest); + } + if(res >= mod){ + res -= mod; + } + if(res < 0){ + res += mod; + } + return dp[pos][nest] = res; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(NULL); + cin >> n; + for (int i=0; i> c; + if (c=='f') a[i] = 1; + else a[i] = 0; + } + memset(dp, -1, sizeof(dp)); + cout << f(1, 0) << "\n"; + + return 0; +} \ No newline at end of file diff --git a/q_number_of_palin.cpp b/q_number_of_palin.cpp new file mode 100644 index 0000000..dcb24b5 --- /dev/null +++ b/q_number_of_palin.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; +int f[5003][5003]; +bool dp[5001][5001]; +int main() { + ios::sync_with_stdio(false); + cin.tie(0); + string s; + cin >> s; + for (int i=0; i> q; + for (int l=3; l<=s.size(); l++) { + for (int i=0; i> l >> r; + cout << (f[l-1][r-1]) << "\n"; + } + return 0; +} \ No newline at end of file diff --git a/rest_stops.cpp b/rest_stops.cpp new file mode 100644 index 0000000..eefe3ea --- /dev/null +++ b/rest_stops.cpp @@ -0,0 +1,30 @@ +// #include +#include +#include +#include +using namespace std; +typedef pair pii; +int main() { + ifstream cin("reststops.in"); + ofstream cout("reststops.out"); + int l, n, rf, rb; + cin >> l >> n >> rf >> rb; + int mul = rf-rb; + vector p(n); + for (int i=0; i> p[i].first >> p[i].second; + } + sort(p.begin(), p.end(), [&](pii a, pii b) { + return a.second > b.second; + }); + + long long ans = 1ll*mul*p[0].first*p[0].second; + int covered = p[0].first; + for (int i=1; i +using namespace std; + +struct rmq { + vector a; + vector tr1, tr2; + int n; + rmq(vector b) { + n = b.size(); + a = b; + tr1.resize(4*n); + tr2.resize(4*n); + build(1, 0, n-1); + } + + int getSize(int x) { + int i=1; + while (i<<1 <= n) i<<=1; + return i<<1; + } + + bool f1(int i, int j) { + return a[i] < a[j]; + } + + bool f2(int i, int j) { + return a[i] > a[j]; + } + + void build(int node, int l, int r) { + if (l==r) { + tr1[node] = tr2[node] = l; + return; + } + int left = node<<1, right = left|1; + build(left, l, (l+r)>>1); + build(right, ((l+r)>>1) + 1, r); + tr1[node] = f1(tr1[node<<1], tr1[(node<<1)|1]) ? tr1[left] : tr1[right]; + tr2[node] = f2(tr2[node<<1], tr2[(node<<1)|1]) ? tr2[left] : tr2[right]; + } + + int mn(int l, int r) { + return mn(1, 0, n-1, l, r); + } + + int mx(int l, int r) { + return mx(1, 0, n-1, l, r); + } + + int mn(int p, int l, int r, int i, int j) { + if (i>r || j=r) return tr1[p]; + int left = p << 1, right = left|1, mid = (l+r)>>1; + int lans = mn(left, l, mid, i, j); + int rans = mn(right, mid+1, r, i, j); + if (lans != -1 and rans!=-1) { + return f1(lans, rans) ? lans : rans; + } else if(lans == -1) return rans; + else return lans; + } + + int mx(int p, int l, int r, int i, int j) { + if (i>r || j=r) return tr2[p]; + int left = p << 1, right = left|1, mid = (l+r)>>1; + int lans = mx(left, l, mid, i, j); + int rans = mx(right, mid+1, r, i, j); + if (lans != -1 and rans!=-1) { + return f2(lans, rans) ? lans : rans; + } else if(lans == -1) return rans; + else return lans; + } +}; + +int main() { + vector a; + srand(time(0)); + for (int i=0; i<10; i++) { + a.push_back((rand()%100 + 1)); + cout << a.back() << " "; + } + cout << "\n"; + rmq ds(a); + for (int i=0; i<10; i++) { + int l = rand()%10; + int r = rand()%10; + if (l > r) swap(l, r); + int mn = rand()%2; + if (mn) { + cout << "min from " << l+1 << " to " << r+1 << " is " << a[ds.mn(l, r)] << "\n"; + } else { + cout << "max from " << l+1 << " to " << r+1 << " is " << a[ds.mx(l, r)] << "\n"; + } + } + return 0; +} \ No newline at end of file diff --git a/round_subset.cpp b/round_subset.cpp new file mode 100644 index 0000000..9f53114 --- /dev/null +++ b/round_subset.cpp @@ -0,0 +1,40 @@ +#include +#include +using namespace std; +const int N = 205; +const int M = 30 * N;// can go 5^30 each number +int dp[N][M]; +int n , k; +long long arr[N]; +int ans; +int get(long long val , int p){ + int res = 0; + while(val % p == 0){ + ++res; + val /= p; + } + return res; +} +int main(){ + scanf("%d %d" , &n , &k); + for(int i = 0 ; i < N ; ++i){ + for(int j = 0 ; j < M ; ++j){ + dp[i][j] = -64 * N; + } + } + dp[0][0] = 0; + for(int i = 1 ; i <= n ; ++i){ + scanf("%lld" , arr + i); + int pw2 = get(arr[i] , 2); + int pw5 = get(arr[i] , 5); + for(int j = min(k , i) ; j >= 1 ; --j){ + for(int l = n * 30 ; l >= pw5 ; --l){ + dp[j][l] = max(dp[j][l] , dp[j - 1][l - pw5] + pw2); + } + } + } + for(int l = n * 30 ; l >= 0 ; --l){ + ans = max(ans , min(l , dp[k][l])); + } + printf("%d\n" , ans); +} \ No newline at end of file diff --git a/sort.in b/sort.in new file mode 100644 index 0000000..5059fef --- /dev/null +++ b/sort.in @@ -0,0 +1,6 @@ +5 +1 +8 +5 +3 +2 diff --git a/sort.out b/sort.out new file mode 100644 index 0000000..7cabb01 --- /dev/null +++ b/sort.out @@ -0,0 +1,6 @@ +0 +1 +2 +1 +1 +2 diff --git a/sorts.in b/sorts.in new file mode 100644 index 0000000..5059fef --- /dev/null +++ b/sorts.in @@ -0,0 +1,6 @@ +5 +1 +8 +5 +3 +2 diff --git a/star_sky.cpp b/star_sky.cpp new file mode 100644 index 0000000..71e34df --- /dev/null +++ b/star_sky.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; +int f[101][101][11]; +int main() { + int n, q, c, x1, y1, x2, y2, t; + cin >> n >> q >> c; + for (int i=1; i<=n; i++) { + cin >> x1 >> y1 >> t; + f[x1][y1][t]++; + } + for(int i=1; i<=100; i++){ + for(int j=1; j<=100; j++){ + for(int k=0; k<=10; k++){ + f[i][j][k] += f[i-1][j][k] + f[i][j-1][k]-f[i-1][j-1][k]; + } + } + } + while (q--) { + cin >> t >> x1 >> y1 >> x2 >> y2; + int temp[11]; + for(int i=0; i<=10; i++){ + temp[i] = f[x2][y2][i] + f[x1-1][y1-1][i] - f[x1-1][y2][i] - f[x2][y1-1][i]; + } + long long ans=0; + for(int i=0; i<=10; i++){ + ans += 1ll*(i+t)%(c+1) * temp[i]; + } + cout << ans << endl; + } + return 0; +} \ No newline at end of file diff --git a/swap_adjacent.cpp b/swap_adjacent.cpp new file mode 100644 index 0000000..525db49 --- /dev/null +++ b/swap_adjacent.cpp @@ -0,0 +1,28 @@ +#include +using namespace std; + +int main() { + int n, j=0; + cin >> n; + string s; + int a[n]; + for (int i=0; i> a[i]; + cin >> s; + for (int i=0; i+1 +#include +#include +#include +#include +using namespace std; +const int mx = 401; + +int grid[mx][mx]; +int vis[mx][mx]; +int n; + +bool safe(int i, int j) { + return (i=0) && (j=0) && (grid[i][j]==1); +} + +bool kill(int i, int j) { + if (vis[i][j] == 1) return false; + if (!safe(i, j)) return false; + if (i == (n-1)) return true; + vis[i][j] = 1; + if (kill(i-1, j-1)) return true; + if (kill(i-1, j)) return true; + if (kill(i, j-1)) return true; + if (kill(i, j+1)) return true; + if (kill(i+1, j+1)) return true; + if (kill(i+1, j)) return true; + return false; +} + + +bool solve() { + memset(grid, -1, sizeof grid); + memset(vis, -1, sizeof vis); + string s; + // cout << " solving\n"; + for (int i=0; i> s; + for (int j=0; j> n; + while (n != 0) { + cout << cnt << " "; + if (solve()) { + cout << "B\n"; + } else { + cout << "W\n"; + } + cnt++; + cin >> n; + } +} \ No newline at end of file diff --git a/uva352.cpp b/uva352.cpp new file mode 100644 index 0000000..43e184a --- /dev/null +++ b/uva352.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +using namespace std; +const int mx = 401; + +int grid[mx][mx]; +int vis[mx][mx]; +int n; + +bool safe(int i, int j) { + return (i=0) && (j=0) && (grid[i][j]==1); +} + +void kill(int i, int j) { + if (vis[i][j] == 1) return; + if (!safe(i, j)) return ; + + vis[i][j] = 1; + // cout << i << " " << j << endl; + + kill(i-1, j-1); + kill(i-1, j); + kill(i-1, j+1); + + kill(i, j-1); + kill(i, j+1); + + kill(i+1, j-1); + kill(i+1, j); + kill(i+1, j+1); + return; +} + + +int solve() { + // memset(grid, -1, sizeof grid); + memset(vis, 0, sizeof vis); + string s; + // cout << " solving\n"; + for (int i=0; i> s; + for (int j=0; j> n) { + cout << "Image number " << cnt << " contains " << solve() << " war eagles.\n"; + cnt++; + } +} \ No newline at end of file diff --git a/vacation.cpp b/vacation.cpp new file mode 100644 index 0000000..3d91eaa --- /dev/null +++ b/vacation.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; + +int main() { + int n; + cin >> n; + int a[n]; + for (int i=0; i> a[i]; + } + int evg=0,oddg=0,evs=0,odds=0, bothe=0, bothodd=0; + for (int i=0;i>1)&1; + if ((a[i]&3) ==3) bothe++; + } else { + oddg +=a[i]&1; + odds += (a[i]>>1)&1; + if ((a[i]&3)==3) bothodd++; + } + } + // cout << evg << " " << evs << " "< +using namespace std; + +int main() { + int n, d; + string s; + cin >> n >> d >> s; + // cout << s << "\n"; + int dp[n+1]; + for (int i=0; i<=n; i++) dp[i] = 1234567890; + dp[0] = dp[1] = 0; + for (int i=1; i<=n; i++) { + if (s[i-1] == '1') { + for (int j=max(1, i-d); j