IOS Mapkit navigation and geo-transcoding helper Classes

Source: Internet
Author: User

Problem 2167, the king told me to patrol the mountains.

Do the second question hehe

Problem 2168 Defensive positions I

Do the first question

Hit the draft and cut it right away.

Suppose the current x= (AI) *1+ (ai+1) *2+ (ai+2) *3+ "' + (AJ) *m

Next time is (ai+1) *1+ (ai+2) *2+ (ai+3) *3+ "' + (aj+1) *m = (AI) *1+ (ai+1) *2+ (ai+2) *3+" "+ (AJ) *m+ (aj+1) * (m+1 )-( ai+ (ai+1) + (ai+2) + "+ (AJ) + (aj+1))

This section of Purple is a continuous direct prefix and preprocessing

#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int maxn = 1000010; int N, m;int a[maxn];int b[maxn];int main () {while (scanf ("%d%d", &n, &m)! = EOF) {__int64 ans = 0;for (int i = 1; i <= N; i++) {scanf ("%d", &a[i]), b[i] = b[i-1] + a[i];if (i <= m) ans + = i*a[i];} __int64 x = ans;for (int i = m+1; I <= n; i++) {__int64 temp = x + (m+1) * a[i];temp-= b[i]-b[i-m-1];x = Temp;ans = ma X (ans, temp);} printf ("%i64d\n", ans);} return 0;}

Problem 2169 Shadow

Do the third question

Started to want to go straight, but the army that was wiped out cannot be destroyed at the start of the process. And then I thought about it.

If some of the troops go through the shortest points on the same point, then they're going to be the same way, so direct contine.

In addition, the sum of Sum[u] represents the total number of troops that have been eliminated before this point to U.

#include <cstdio> #include <cstring> #include <queue> #include <vector>using namespace std; const int MAXN = 100010;int d[maxn];int sum[maxn];int a[maxn];int b[maxn];int vis[maxn];vector <int> G[maxn];int N,  M;void BFS () {queue <int> q;for (int i = 0; I <= N; i++) D[i] = 999999999;memset (sum, 0, sizeof (sum)); for (int i = 1; I <= m; i++) {Q.push (b[i]);d [b[i]] = 0;vis[b[i]] = 1;} while (! Q.empty ()) {int u = q.front (); Q.pop (); for (int i = 0; i < g[u].size (); i++) {int v = g[u][i];if (Vis[v]) {Sum[v] + = sum[u];sum[u] = 0;continue;} VIS[V] = true;if (D[v] > D[u] + 1) {Sum[v] + = Sum[u] + a[v];sum[u] = 0;d[v] = D[u] + 1; Q.push (v);}}} int main () {while (scanf ("%d%d", &n, &m)! = EOF) {for (int i = 0; I <= N; i++) {g[i].clear ();} for (int i = 1; I <= n; i++) {scanf ("%d", &a[i]);} for (int i = 1; I <= m; i++) {scanf ("%d", &b[i]);} for (int i = 1; i < n; i++) {int u, v;scanf ("%d%d", &u, &v); G[u].push_back (v); G[v].push_back (u);} memset (Vis, 0, siZeof (VIS)); BFS (); int ans = 0;for (int i = 1; I <= n; i++) ans + sum[i];p rintf ("%d\n", ans);} return 0;}

Problem 2170 sequence of peanuts

Because chat to see the animation no time, I would like to see the question of the free to think again

problem 2171 defensive positions II

Do the fourth question

Look at the next topic of the tree segment UPDATE!!!! Direct Line segment Tree It's disgusting, but it's a water problem.

#include <stdio.h> #define MAX 100010struct node{int l;int r;int sum;int add;} a[max*4];void Build (int l,int R,int rt) {A[RT].L = L;A[RT].R = R;a[rt].add = 0;if (L = = r) {scanf ("%d", &a[rt].sum); retur n;} int m = (L + R) >> 1;build (l,m,rt<<1); build (m+1,r,rt<<1|1); a[rt].sum = A[rt<<1].sum + a[rt<&lt ; 1|1].sum;} void update (int l,int r,int rt,int Add) {if (A[RT].L = = L && A[RT].R = r) {A[rt].add + = add;a[rt].sum + = Add * (r-l+ 1); return;} if (a[rt].l = = A[RT].R) return;if (a[rt].add) {int k = a[rt].r-a[rt].l + 1;a[rt<<1].add + = a[rt].add;a[rt<<1|1] . Add + = A[rt].add;a[rt<<1].sum + = a[rt].add* (K-(k>>1)); A[rt<<1|1].sum + = a[rt].add* (k>>1); a[ Rt].add = 0;} int m = (a[rt].l + a[rt].r) >> 1;if (r <= m) update (L,R,RT&LT;&LT;1,ADD); else if (L > M) update (L,R,RT&LT;&LT;1|1, add); Else{update (l,m,rt<<1,add); update (M+1,R,RT&LT;&LT;1|1,ADD);} A[rt].sum = A[rt<<1].sum + a[rt<<1|1].sum;} int query (int l, int r, int RT) {if (A[RT].L = = L && A[RT].R = r) {return a[rt].sum;} if (a[rt].l = = A[RT].R) return 0;if (a[rt].add) {int k = a[rt].r-a[rt].l + 1;a[rt<<1].add + = a[rt].add;a[rt<<1|1 ].add + = A[rt].add;a[rt<<1].sum + a[rt].add* (K-(k>>1)); A[rt<<1|1].sum + = a[rt].add* (k>>1); a [Rt].add = 0;} int m = (a[rt].l + A[RT].R) >> 1;int res = 0;if (r <= m) res = query (l,r,rt<<1); else if (L > m) res = query ( L,R,RT&LT;&LT;1|1); Else{res + = query (l,m,rt<<1); res + = query (m+1,r,rt<<1|1);} A[rt].sum = a[rt<<1].sum + A[rt<<1|1].sum;return res;} int main () {int n, m, Q;while (scanf ("%d%d%d", &n, &m, &q)! = EOF) {build (1, N, 1), while (q--) {int x;scanf ("%d", &x);p rintf ("%d\n", query (x, x+m-1, 1)); Update (x, X+m-1, 1,-1);}} return 0;}


Problem 2172, I patrol the hills.

I didn't see it.

problem 2173 Nostop

Do the fifth question

The first feeling is that the floyd+ matrix is fast power 1 billion times Floyd certainly not. Matrix Fast power acceleration AH

Do more to do the classic topic Ah!!! POJ 3613 That's a lot of classic questions. We're going to learn the classics and extrapolate.

#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const __int64 fd = 1;const __int64 INF = fd<<55;const int maxn = 55;struct mat{__int64 a[maxn][maxn];}; Mat A, B, C, D;int N, M; Mat Floyd (Mat X, Mat y) {mat z;for (int i = 1; I <= n; i++) for (int j = 1; J <= N; j + +) {Z.a[i][j] = INF;} for (int k = 1; k <= N; k++) for (int i = 1; I <= n; i++) for (int j = 1; J <= N; j + +) Z.a[i][j] = min (z.a[i][j], x.a[ I][K] + y.a[k][j]); return z;}    /*mat Get (Mat X, Mat y) {mat z;    memset (z.a, 0, sizeof (Z.A));            for (int i = 1, i <= N; i++) for (int j = 1; J <= N; j + +) for (int k = 1; k <= N; k++)                {Z.a[i][j] + = x.a[i][k]*y.a[k][j];            Z.A[I][J]%= mod; } return Z;}        */void mat_pow (int x) {while (x) {if (x&1) B = Floyd (b, A);        A = Floyd (A, a);    x >>= 1; }}int Main () {int t;scanf ("%d", &t), while (t--) {int x;scanf ("%d%d%d", &n, &m, &x); for (int i = 1; I <= N; i++) for (int j = 1; J <= N; j + +) {A.a[i][j] = b.a[i][j] = inf;if (i = = j) B.a[i][j] = 0;} while (m--) {int u, V;__int64 w;scanf ("%d%d%i64d", &u, &v, &w), if (A.a[u][v] > W) a.a[u][v] = w;} Mat_pow (x), if (b.a[1][n] = = INF) puts ("1"), elseprintf ("%i64d\n", B.a[1][n]);} return 0;}


Problem 2174 rolls of Fortune puzzle

I didn't see it.

Finally summarize the previous 4 questions are 1 A of the last problem forget to deal with-1 of the situation PIT!!!

But I'm going to have to work harder on one aspect.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.