http://mlz000.github.io/2015/07/14/srm-538/
題外話
之前準備期末預習加上剛放假浪了一會= =沒有補題,今天開始恢復補題。。
250
Description:
平面上給出
Solution
顯然如果要求是偶的話只有全奇時無解,若有一個偶數,則可通過往返的方式訪問其他點最後停留在偶數點,要求爲奇數時同理
Code
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
class EvenRoute {
public:
string isItPossible(vector <int> x, vector <int> y, int wantedParity) {
int n = x.size();
bool even = 0, odd = 0;
for (int i = 0; i < n; ++i) {
if ((abs(x[i]) + abs(y[i])) & 1) odd = 1;
else even = 1;
}
return (odd && even) || (even && !wantedParity) || (odd && wantedParity) ? "CAN" : "CANNOT";
}
};
450
Description
給出四種命令。左轉多少度,右轉多少度,前進多遠,後退多遠。先在順序是打亂的。要求給出一種排列使得最終總的位移和最遠。輸出最遠距離即可。
Solution
一個很明顯的直觀感受是儘量走直線會使得答案更大一些。這樣就很簡單了,不妨全向前,然後把調整角度放到後面,最後全向後即可。調整的角度揹包求即可
Code
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
vector<int> a, b;//ang back
int dp[60][360];
const double Pi = acos(-1.0);
class TurtleSpy {
public:
double maxDistance(vector <string> commands) {
int n = commands.size();
double X = 0.0, Y = 0.0;
for (int i = 0; i < n; ++i) {
char s[10];
int x;
sscanf(commands[i].c_str(), "%s%d", s, &x);
if (s[0] == 'f') X += x;
else if (s[0] == 'b') Y += x;
else if (s[0] == 'l') a.pb(x);
else a.pb(360 - x);
}
dp[0][0] = 1;
for (int i = 0; i < a.size(); ++i) {
for (int j = 0; j < 360; ++j)
if (dp[i][j]) dp[i + 1][(j + a[i]) % 360] = dp[i + 1][j] = 1;
}
double t = 0.0;
for (int i = 0; i < 360; ++i) {
if (dp[a.size()][i]) t = max(t, X * X + Y * Y - 2.0 * X * Y * cos(Pi * i / 180.0));
}
return sqrt(t);
}
};