[Boring test events] T7 luxury cruise

Observe the subject and found that you can move forward much greed can go forward much, then try to twist 180 degrees backwards. The remaining angle by in situTwisted assImplement, and does not affect the distance

Two variables were recorded from the open forward and backward walking. Angle of only one array, referred to as a left \ (\ Theta \) , the right referred to as \ (360- \ theta \) of

How to find the nearest \ (180 \) ? Knapsack ...

How to find the answer? Suppose we from \ ((0,0) \) departure, if it finds the end of \ (x \) and \ (y \) can be obtained using the Pythagorean theorem distance .x value moving forward value * go back value \ (COS (\ Theta) \) , the value of Y values to go back * \ (SiN (\ Theta) \)

Blue and green angle we seek out, trigonometry can find x and y

#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
const int mod = 360;
const int MAXN = 725;
int n, fwd,bwd,tot,degree = mod;
double x_coord, y_coord;
int pos[MAXN];
int dp[MAXN * mod];
bool vis[MAXN*mod];
double dist(double a, double b){
  return sqrt(a*a+b*b);
}//勾股定理
const double pi = 3.1415926535897932;
double cvt(double deg){
    double angle = deg;
    double result =(angle * pi)/180;
    return result;
}//角度转化为弧度
int main(){
  cin >> n;
  for (int i=0;i<n;i++){
    string a;int b;cin >> a >> b;
    if(a[0]=='f') fwd+=b;
    else if (a[0]=='b') bwd += b;
    else if (a[0]=='l') pos[++tot] = b%mod;
    else pos[++tot] = 360-(b%mod);
  }
  vis[0] = true;
  for (int i=1;i<=tot;i++){
    for (int j=MAXN*n;j>=0;j--){
      if (pos[i]>j) break;
      if (vis[j-pos[i]]){
        vis[j] = true;
        degree = min(degree,abs((j%mod)-180));
      }//背包
    }
  }
  x_coord = (double)fwd+(double)bwd*cos(cvt(degree));
  y_coord = (double)bwd * (double)sin(cvt(degree));
  //找x和y的值
  printf("%.6f",dist(x_coord,y_coord));
}

Guess you like

Origin www.cnblogs.com/DannyXu/p/12536355.html
T7