1. POJ 1088
#include <cstdio> #include <cmath> #include <stdlib.h> #include <map> #include <set># include<time.h> #include <vector> #include <queue> #include <string> #include <string.h> #include <iostream> #include <algorithm>using namespace std, #define EPS 1e-8#define PI acos ( -1.0) #define INF 0x3f3f3f3f#define LL long Long#define max (a) > (b)? ( A):(b) #define MIN (a) < (b) ( A):(B)) typedef pair<int, int> PII; #define MAXN + 10int d[maxn][maxn];int a[maxn][maxn];int go[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};int R, C;int ans;int dfs (int x, int y) {if (D[x][y] > 0) return d[x][y]; int res = 0; for (int i = 0; i < 4; i++) {int dx = x + go[i][0]; int dy = y + go[i][1]; if (DX < 1 | | Dy < 1 | | dx > R | | dy > C | | a[dx][dy] >= a[x][y]) continue; int t = DFS (dx, dy); res = max (res, t); } res++; ans = max (ans, res); return D[x][y] = res;} int main () { while (~SCANF ("%d%d", &r, &c)) {ans =-inf; for (int i = 1; I <= R; i++) for (int j = 1; J <= C; j + +) scanf ("%d", &a[i][j]); memset (d,-1, sizeof D); for (int i = 1; I <= R; i++) for (int j = 1; J <= C; j + +) if (D[i][j] < 0) Dfs (i, j); printf ("%d\n", ans); } return 0;}
2.poj2299
#include <cstdio> #include <cmath> #include <stdlib.h> #include <map> #include <set># include<time.h> #include <vector> #include <queue> #include <string> #include <string.h> #include <iostream> #include <algorithm>using namespace std, #define EPS 1e-8#define PI acos ( -1.0) #define INF 0x3f3f3f3f#define LL long Long#define max (a) > (b)? ( A):(b) #define MIN (a) < (b) ( A):(B)) typedef pair<int, int> PII; #define MAXN 500000 + 10int a[maxn];int n;int lowbit (int x) {return x & (- x);} void Modify (int x,int add)//one-dimensional {while (x<=n) {a[x]+=add; X+=lowbit (x); }}int get_sum (int x) {int ret=0; while (x > 0) {ret+=a[x]; X-=lowbit (x); } return ret;} Map<int, int> m;set<int> s;struct b{int x, POS;} B[maxn];int CMP (b t1, b T2) {return t1.x < t2.x;} int Bb[maxn];int Main () {while (~SCANF ("%d", &n) && N) {for (int i = 1; I <= N;i++) {scanf ("%d", &b[i].x); B[i].pos = i; } sort (b + 1, B + 1 + N, CMP); for (int i = 1; I <= n; i++) Bb[b[i].pos] = i; memset (A, 0, sizeof a); LL ans = 0; for (int i = 1; I <= n; i++) {modify (Bb[i], 1); Ans + = I-get_sum (Bb[i]); } printf ("%i64d\n", ans); } return 0;} /*59105431230*/
3. Hdu
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring>using namespace STD; #define MAXN 400000 + 10int L[MAXN], r[maxn];int pos[maxn];int a[maxn];int n;void get_left () {int head = 1, tail = 0; for (int i = 1; I <= N, i++) {while (Head <= tail && a[pos[tail]] >= a[i]) tail--; L[i] = I-pos[tail]-1; Pos[++tail] = i; }}void get_right () {int head = 1, tail = 0; Pos[tail] = n + 1; for (int i = n, i >= 1; i--) {while (Head <= tail && a[pos[tail]] >= a[i]) tail--; R[i] = Pos[tail]-i-1; Pos[++tail] = i; }}int Main () {while (~SCANF ("%d", &n) {memset (l, 0, sizeof L); memset (r, 0, sizeof R); for (int i = 1; I <= n; i++) scanf ("%d", A + i); Get_left (); Get_right (); for (int i = 1; I <= n; i++) {printf ("%d *%d\n", l[i], r[i]); } Long Longans =-1; for (int i = 1; I <= n; i++) ans = max (ans, (long long) l[i] + r[i] + 1) * a[i]); printf ("%i64d\n", ans); } return 0;} /*65 8 4 4 8 4*/
4.hdu 1541
#include <cstdio> #include <cmath> #include <stdlib.h> #include <map> #include <set># include<time.h> #include <vector> #include <queue> #include <string> #include <string.h> #include <iostream> #include <algorithm>using namespace std, #define EPS 1e-8#define PI acos ( -1.0) #define INF 0x3f3f3f3f#define LL long Long#define max (a) > (b)? ( A):(b) #define MIN (a) < (b) ( A):(B)) typedef pair<int, int> PII; #define N 32010#define maxn 15010int n;int a[n];int ans[maxn];int lowbit (int x) { return x & (-X);} void Modify (int x, int add) {while (x <= N) {A[x] + = add; x + = Lowbit (x); }}int get_sum (int x) {int ret = 0; while (x > 0) {ret + = a[x]; X-= Lowbit (x); } return ret;} int main () {while (~SCANF ("%d", &n)) {int x, y; memset (ans, 0, sizeof ans); memset (A, 0, sizeof a); for (int i = 0; i < n; i++) {scanf ("%d%D ", &x, &y); x + +; Ans[get_sum (x)]++; Modify (x, 1); } for (int i = 0; i < n; i++) printf ("%d\n", Ans[i]); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Cut a few water questions to review