跳过正文
  1. Posts/

poj 2926 Requirements (五维曼哈顿距离变换【拆点】)

·1 分钟

http://poj.org/problem?id=2926 题意:给出n(1E5)个五维空间内的坐标…问最远的两个点距离多少。 思路:拆点即可。去绝对值。可以由二维空间推广到k维空间。一个点可以拆成2^(k-1)个点。 具体见代码。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年02月25日 星期四 00时19分46秒
 4File Name :code/poj/2926.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#include <iomanip>
20#define fst first
21#define sec second
22#define lson l,m,rt<<1
23#define rson m+1,r,rt<<1|1
24#define ms(a,x) memset(a,x,sizeof(a))
25typedef long long LL;
26#define pi pair < int ,int >
27#define MP make_pair
28
29using namespace std;
30const double eps = 1E-8;
31const int dx4[4]={1,0,0,-1};
32const int dy4[4]={0,-1,1,0};
33const int inf = 0x3f3f3f3f;
34const int N=1E5+7;
35double p[16][N];
36int n;
37int main()
38{
39	#ifndef  ONLINE_JUDGE
40	freopen("code/in.txt","r",stdin);
41  #endif
42
43	ios::sync_with_stdio(false);
44	cin>>n;
45	for ( int i = 0 ; i < n ;i++)
46	{
47	    double x1,x2,x3,x4,x5;
48	    cin>>x1>>x2>>x3>>x4>>x5;
49	    p[0][i]=x1+x2+x3+x4+x5;
50	    p[1][i]=x1+x2+x3+x4-x5;
51	    p[2][i]=x1+x2+x3-x4+x5;
52	    p[3][i]=x1+x2+x3-x4-x5;
53
54	    p[4][i]=x1+x2-x3+x4+x5;
55	    p[5][i]=x1+x2-x3+x4-x5;
56	    p[6][i]=x1+x2-x3-x4+x5;
57	    p[7][i]=x1+x2-x3-x4-x5;
58
59	    p[8][i]=x1-x2+x3+x4+x5;
60	    p[9][i]=x1-x2+x3+x4-x5;
61	    p[10][i]=x1-x2+x3-x4+x5;
62	    p[11][i]=x1-x2+x3-x4-x5;
63
64	    p[12][i]=x1-x2-x3+x4+x5;
65	    p[13][i]=x1-x2-x3+x4-x5;
66	    p[14][i]=x1-x2-x3-x4+x5;
67	    p[15][i]=x1-x2-x3-x4-x5;
68	}
69
70	double mx = -1;
71	for ( int i = 0 ; i < 16 ; i++)
72	{
73	    sort(p[i],p[i]+n);
74
75	    mx = max(mx,p[i][n-1]-p[i][0]);
76
77	}
78	cout<<fixed<<setprecision(2)<<mx<<endl;
79
80
81  #ifndef ONLINE_JUDGE
82  fclose(stdin);
83  #endif
84    return 0;
85}

相关文章

bzoj 1604: [Usaco2008 Open]Cow Neighborhoods 奶牛的邻居 (曼哈顿距离的转化【拆点】+set+并查集)

http://www.lydsy.com/JudgeOnline/problem.php?id=1604 题意:了解奶牛们的人都知道,奶牛喜欢成群结队.观察约翰的N(1≤N≤100000)只奶牛,你会发现她们已经结成了几个“群”.每只奶牛在吃草的时候有一个独一无二的位置坐标Xi,Yi(l≤Xi,Yi≤[1..10^9];Xi,Yi∈整数.当满足下列两个条件之一,两只奶牛i和j是属于同一个群的: 1.两只奶牛的曼哈顿距离不超过C(1≤C≤10^9),即lXi - xil+IYi - Yil≤C. 2.两只奶牛有共同的邻居.即,存在一只奶牛k,使i与k,j与k均同属一个群. 给出奶牛们的位置,请计算草原上有多少个牛群,以及最大的牛群里有多少奶牛

nthu 10925 - Advanced Heap Sort

·2 分钟
http://140.114.86.238/problem/10925/ Description 有兩個序列S1和S2,各有N個元素。當我們在S1,S2各取一個數字時,總共會有NN這麼多可能的”和”(sum)。請找出這NN這麼多和裡最小的N個值,並將它們加總後輸出。

bzoj2002: [Hnoi2010]Bounce 弹飞绵羊 (分块)

·1 分钟
http://www.lydsy.com/JudgeOnline/problem.php?id=2002 题意+思路: 同codeforces 13 E holes. 1/* *********************************************** 2Author :111qqz 3Created Time :2016年02月21日 星期日 02时29分39秒 4File Name :code/bzoj/2002.cpp 5************************************************ */ 6 7#include <cstdio> 8#include <cstring> 9#include <iostream> 10#include <algorithm> 11#include <vector> 12#include <queue> 13#include <set> 14#include <map> 15#include <string> 16#include <cmath> 17#include <cstdlib> 18#include <ctime> 19#define fst first 20#define sec second 21#define lson l,m,rt<<1 22#define rson m+1,r,rt<<1|1 23#define ms(a,x) memset(a,x,sizeof(a)) 24typedef long long LL; 25#define pi pair < int ,int > 26#define MP make_pair 27 28using namespace std; 29const double eps = 1E-8; 30const int dx4[4]={1,0,0,-1}; 31const int dy4[4]={0,-1,1,0}; 32const int inf = 0x3f3f3f3f; 33const int N=2E5+7; 34int n,m; 35int siz = 450; //sqrt(2E5) 36int a[N]; 37int pos[N]; 38int cnt[N]; 39int nxt[N]; 40int end[N]; 41 42 43void go( int x) 44{ 45 int ans = 0 ; 46 while (1) 47 { 48 if (x>=n) 49 { 50 printf("%d\n",ans); 51 break; 52 } 53 ans +=cnt[x]; 54 x = nxt[x]; 55// cout<<"nxt[x]:"<<nxt[x]<<endl; 56 } 57} 58void update ( int i,int j) 59{ 60 if (j>=n) 61 { 62 cnt[i]=1; 63 nxt[i]=n; 64 end[i]=i; 65 } 66 else 67 { 68 if (pos[i]==pos[j]) 69 { 70 cnt[i] = cnt[j] + 1; 71 nxt[i] = nxt[j]; 72 end[i]=end[j]; 73 } 74 else 75 { 76 cnt[i] = 1; 77 nxt[i] = j; 78 end[i] = end[j]; 79 } 80 } 81} 82int main() 83{ 84 #ifndef ONLINE_JUDGE 85 freopen("code/in.txt","r",stdin); 86 #endif 87 88 scanf("%d",&n); 89 for ( int i = 0 ; i < n ;i++) 90 { 91 scanf("%d",&a[i]); 92 pos[i] = i/siz; 93 } 94 95 for ( int i = n - 1 ; i >= 0 ; i--) update(i,i+a[i]); 96 97 scanf("%d",&m); 98 while (m--) 99 { 100 int opt; 101 scanf("%d",&opt); 102 if (opt==1) 103 { 104 int x; 105 scanf("%d",&x); 106 go(x); 107 } 108 else 109 { 110 int x,y; 111 scanf("%d %d",&x,&y); 112 a[x]=y; 113 update(x,x+a[x]); 114 int p = pos[x]*siz; 115 for ( int i = x-1 ; i >= p ; i--) update(i,i+a[i]); 116 } 117 } 118 119 #ifndef ONLINE_JUDGE 120 fclose(stdin); 121 #endif 122 return 0; 123}