Water a-two Bases
Water problem, but the accuracy of the POW is not high, was hack off. With a long long can save the next
#include <bits/stdc++.h>using namespace Std;typedef long long ll;const int N = 1e5 + 10;const int INF = 0x3f3f3f3f;i NT B1[44], B2[44];int N, m;ll _pow (int m, int x) {LL ret = 1;for (int i=1; i<=x; ++i) {ret *= m;} return ret;} int main (void) {cout << (LL) POW (9) << endl;cout << _pow (9) << endl;scanf ("%d%d", &n , &m); ll ans1 = 0, ans2 = 0;for (int i=1; i<=n; ++i) {scanf ("%d", &b1[i]);} for (int i=n; i>=1;-I.) {ANS1 + = _pow (M, n-i) * b1[i];} scanf ("%d%d", &n, &m); for (int i=1; i<=n; ++i) {scanf ("%d", &b2[i]);} for (int i=n; i>=1;-I.) {ANS2 + = _pow (M, n-i) * b2[i];} if (Ans1 < ANS2) puts ("<"), else if (ans1 > Ans2) puts (">"), elseputs ("="); return 0;} /*9 3910 20 16 36 30 29 28 9 89 3812 36 10 22 6 3 19 12 34*/
Ruler b-approximating a Constant Range
The simplest is to maintain the maximum and minimum values of the [I, j] interval and their final position.
#include <bits/stdc++.h>using namespace Std;typedef long long ll;const int N = 1e5 + 10;const int INF = 0x3f3f3f3f;i NT A[n];int Main (void) {int n;scanf ("%d", &n), for (int i=1; i<=n; ++i) {scanf ("%d", &a[i]);} int ans = 1, MN = a[1], mx = a[1], i = 1, j = 2;int P1 = 1, p2 = 1;while (j <= N) {if (A[j] <= mn) {mn = A[j];p 1 = j;} else if (A[j] >= mx) {mx = a[j];p 2 = j;} if (mx-mn <= 1) {ans = max (ans, j-i + 1);} Else{while (Mx-mn > 1) {if (P1 < P2 && p1 + 1 <= j) {mn = A[p1+1];i = p1 + 1;p1++;} else if (P1 >= p2 && p2 + 1 <= j) {mx = A[p2+1];i = p2 + 1;p2++;} Elsebreak;} ans = max (ans, j-i + 1);} j + +;} printf ("%d\n", ans); return 0;}
BFS c-the Routes
Between two points is not the subway or the car, then 1 to n is the same, as long as a BFS on the line, water.
I just made a two-way BFS, want to set a try, write trouble, but still a dropped, think or have problems, vis array has problems, data water.
#include <bits/stdc++.h>using namespace Std;typedef long long ll;const int N = 4e2 + 10;const int M = N * N;const in T INF = 0x3f3f3f3f;struct Edge{int V, W, NEX; Edge () {}edge (int v, int W, int. NEX): V (v), W (W), NEX (NEX) {}}edge[m];int Head[n];bool lk[n][n];bool vis[n][n][2];bool Vis2[n][2];bool Ok[2];int N, M, e;queue<int> que[2];void init (void) {memset (head,-1, sizeof (head)); e = 0;} void Add_edge (int u, int v, int w) {edge[e].v = V;EDGE[E].W = W;edge[e].nex = Head[u];head[u] = e++;} BOOL BFS (int typ, int tim) {int sz = Que[typ].size (), while (sz--) {int u = que[typ].front (); Que[typ].pop (); for (int I=hea D[u]; ~i; I=edge[i].nex) {int v = edge[i].v, W = edge[i].w;if (w! = Typ) continue;if (v = = N) {Ok[typ] = true;if (ok[typ^1]) return True ;} if (Vis2[v][typ]) continue; Vis2[v][typ] = true;if (vis[v][tim][typ^1]) Continue;vis[v][tim][typ] = True;que[typ].push (v);}} return false;} int run (void) {Que[0].push (1); Que[1].push (1); int step = 0;while (!que[0].emPty () | | !que[1].empty ()) {step++;if (step >) break; if (!ok[0]) {if (BFS (0, Step)) return step; }if (!ok[1]) {if (BFS (1, Step)) return step; }}return-1;} int main (void) {init (); scanf ("%d%d", &n, &m); for (int u, V, i=1; i<=m; ++i) {scanf ("%d%d", &u, &v); add _edge (U, V, 1), Add_edge (V, U, 1); Lk[u][v] = lk[v][u] = true;} int cnt = 0;for (int i=1; i<=n; ++i) {for (int j=i+1; j<=n; ++j) {if (i = = J | | lk[i][j]) Continue;cnt++;add_edge (i, J , 0); Add_edge (J, I, 0);}} if (cnt = = 0) {puts ("-1"); return 0;} printf ("%d\n", run ()); return 0;}
Codeforces Round #333 (Div. 2)