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)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) typedef pair<int , int> pii; #define maxn 100 + 10 int 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)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) typedef pair<int , int> pii; #define maxn 500000 + 10 int a[maxn]; int n; 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; } 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; } /* 5 9 1 0 5 4 3 1 2 3 0 */
3. hdu
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; #define maxn 400000 + 10 int 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 long ans = -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; } /* 6 5 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)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) typedef pair<int , int> pii; #define N 32010 #define maxn 15010 int 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; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-14 11:12:52