日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CodeForces 321A Ciel and Robot(数学模拟)

發(fā)布時(shí)間:2025/3/16 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CodeForces 321A Ciel and Robot(数学模拟) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目鏈接:http://codeforces.com/problemset/problem/321/A

題意:在一個(gè)二維平面中,開始時(shí)在(0,0)點(diǎn),目標(biāo)點(diǎn)是(a,b),問能不能通過重復(fù)操作題目中的指令,從原點(diǎn)移動(dòng)到目標(biāo)點(diǎn)。

分析:假設(shè)一次完成所有的命令后,移動(dòng)到了(xx,yy),并且從(Xi,Yi)重復(fù)操作k次指令到達(dá)目標(biāo)點(diǎn),則可以列出方程 Xi + k * xx = a && Yi + k * yy = b,然后解出k,判斷k是否大于等于0即可。

#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef __int64 LL; LL a, b, xx, yy; LL X[150], Y[150]; int len; bool check(LL x, LL y) {LL tmp_x = a - x, tmp_y = b - y;if(xx == 0) {if(yy == 0) {if(tmp_x == 0 && tmp_y == 0) return true;else return false;}else {if(tmp_y % yy == 0) {if(tmp_y / yy >= 0 && tmp_x == 0) return true;else return false;}else return false;}}else {if(yy == 0) {if(tmp_x % xx == 0) {if(tmp_x / xx >= 0 && tmp_y == 0) return true;else return false;}else return false;}else {if(tmp_x % xx == 0 && tmp_y % yy == 0) {if(tmp_x / xx >= 0 && tmp_y / yy >= 0 && tmp_x / xx == tmp_y / yy) return true;else return false;}else return false;}} }int main() {char op[150];while(~scanf("%I64d%I64d", &a, &b)) {scanf("%s", op);if(a == 0 && b == 0) {printf("Yes\n");continue;}len = strlen(op);LL x = 0, y = 0;int FLAG = 0;for(int i = 0; i < len; i++) {if(op[i] == 'U') y++;else if(op[i] == 'D') y--;else if(op[i] == 'L') x--;else if(op[i] == 'R') x++;X[i] = x, Y[i] = y;}xx = X[len-1], yy = Y[len-1];for(int i = 0; i < len; i++) {if(check(X[i], Y[i])) {FLAG = 1;printf("Yes\n");break;}}if(!FLAG) printf("No\n");}return 0; }

總結(jié)

以上是生活随笔為你收集整理的CodeForces 321A Ciel and Robot(数学模拟)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。