枚舉機器人走的最後一步,用終點坐差後計算周期次數
trick:周期次數要>=0
#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; template inline bool rd(T &ret) { char c; int sgn; if (c = getchar(), c == EOF) return 0; while (c != '-' && (c<'0' || c>'9')) c = getchar(); sgn = (c == '-') ? -1 : 1; ret = (c == '-') ? 0 : (c - '0'); while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0'); ret *= sgn; return 1; } template inline void pt(T x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) pt(x / 10); putchar(x % 10 + '0'); } typedef long long ll; typedef pair pii; const int inf = 1e9; const int N = 105; ll a, b; char s[N]; ll x[N], y[N]; int n; bool work() { for (int i = 0; i < n; i++) { ll l = a - x[i]; ll r = b - y[i]; if (x[n] == 0) { if (l)continue; if (y[n] == 0) { if (r)continue; else return true; } if (r%y[n])continue; if(r/y[n] >= 0) return true; else continue; } if (l%x[n])continue; if (l / x[n] < 0)continue; if (y[n] == 0) { if (r)continue; return true; } if (r%y[n])continue; if (l / x[n] == r / y[n]) { if (l / x[n] >= 0)return true; } } return false; } int main() { rd(a); rd(b); scanf(%s, s + 1); n = strlen(s + 1); x[0] = y[0] = 0; for (int i = 1; s[i]; i++) { x[i] = x[i - 1]; y[i] = y[i - 1]; if (s[i] == 'U')y[i] = y[i - 1] + 1; if (s[i] == 'D')y[i] = y[i - 1] - 1; if (s[i] == 'L')x[i] = x[i - 1] - 1; if (s[i] == 'R')x[i] = x[i - 1] + 1; } work() ? puts(Yes) : puts(No); return 0; }
前面一節我們已經把QAction添加到菜單和工
前言對於一個沒有實例化的空類,編譯器不會給它默認生成任何函數
1 新建ActiveX控件工程 2 編
【題目大意】:給出一個整數n,求一個數x,x在1
Hamming Code Time Limit: 1000
本章目的:當Android用ART虛擬機替代Dalvik的時