题意:http://acm.hdu.edu.cn/showproblem.php?pid=4216
有很多向量,你可以反转某些向量,让你尽可能远离0,0点。
思路:
首先贪心是不行的详见C:UsersxxDesktop截图hdu4216.png
dp存放的是,x坐标下的最大值和最小值
1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf islower isupper 3 #include <cstdlib>//malloc exit strcat itoa system("cls") 4 #include <iostream>//pair 5 #include <fstream>//freopen("C:\Users\13606\Desktop\Input.txt","r",stdin); 6 #include <bitset> 7 //#include <map> 8 //#include<unordered_map> 9 #include <vector> 10 #include <stack> 11 #include <set> 12 #include <string.h>//strstr substr strcat 13 #include <string> 14 #include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9; 15 #include <cmath> 16 #include <deque> 17 #include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less 18 #include <vector>//emplace_back 19 //#include <math.h> 20 #include <cassert> 21 #include <iomanip> 22 //#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor 23 #include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare) 24 using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation 25 //****************** 26 clock_t __START,__END; 27 double __TOTALTIME; 28 void _MS(){__START=clock();} 29 void _ME(){__END=clock();__TOTALTIME=(double)(__END-__START)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;} 30 //*********************** 31 #define rint register int 32 #define fo(a,b,c) for(rint a=b;a<=c;++a) 33 #define fr(a,b,c) for(rint a=b;a>=c;--a) 34 #define mem(a,b) memset(a,b,sizeof(a)) 35 #define pr printf 36 #define sc scanf 37 #define ls rt<<1 38 #define rs rt<<1|1 39 typedef pair<int,int> PII; 40 typedef vector<int> VI; 41 typedef unsigned long long ull; 42 typedef long long ll; 43 typedef double db; 44 const db E=2.718281828; 45 const db PI=acos(-1.0); 46 const ll INF=(1LL<<60); 47 const int inf=(1<<30); 48 const db ESP=1e-9; 49 const int mod=(int)1e9+7; 50 const int N=(int)1e2+10; 51 52 int x[N],y[N]; 53 db dis(db x1,db y1,db x2,db y2) 54 { 55 db aa=y1-y2; 56 db bb=x1-x2; 57 return aa*aa+bb*bb; 58 } 59 int dp[103][50000][2]; 60 int tot=0; 61 62 void solve() 63 { 64 int top=50000; 65 for(int i=0;i<103;++i) 66 for(int j=0;j<top;++j) 67 dp[i][j][0]=inf,dp[i][j][1]=-inf; 68 int n,X,Y; 69 sc("%d%d%d",&n,&X,&Y); 70 for(int i=1;i<=n;++i)sc("%d%d",&x[i],&y[i]); 71 int mid=25000;X+=mid; 72 dp[0][mid][0]=dp[0][mid][1]=0; 73 for(int i=1;i<=n;++i) 74 { 75 for(int j=5000;j<top-5000;++j) 76 { 77 int pos; 78 pos=j+x[i]; 79 if(dp[i-1][j][0]!=inf) 80 dp[i][pos][0]=min(dp[i][pos][0],dp[i-1][j][0]+y[i]); 81 82 if(dp[i-1][j][1]!=-inf) 83 dp[i][pos][1]=max(dp[i][pos][1],dp[i-1][j][1]+y[i]); 84 85 pos=j-x[i]; 86 if(dp[i-1][j][0]!=inf) 87 dp[i][pos][0]=min(dp[i][pos][0],dp[i-1][j][0]-y[i]); 88 89 if(dp[i-1][j][1]!=-inf) 90 dp[i][pos][1]=max(dp[i][pos][1],dp[i-1][j][1]-y[i]); 91 } 92 } 93 db ans=0; 94 for(int i=0;i<top;++i) 95 { 96 if(dp[n][i][0]!=inf) 97 { 98 // pr("%d ",i); 99 ans=max(dis(i,dp[n][i][0],X,Y),ans); 100 } 101 if(dp[n][i][1]!=-inf) 102 { 103 // pr("%d ",i); 104 ans=max(dis(i,dp[n][i][1],X,Y),ans); 105 } 106 } 107 db res=ans; 108 pr("Case %d: ",++tot); 109 pr("%.3lf ",sqrt(res)); 110 } 111 112 int main() 113 { 114 int T; 115 sc("%d",&T); 116 while(T--)solve(); 117 return 0; 118 } 119 120 /**************************************************************************************/