CodeForces 321A Ciel and Robot(数学模拟)
题目链接:http://codeforces.com/problemset/problem/321/A
题意:在一个二维平面中,開始时在(0,0)点,目标点是(a。b),问能不能通过反复操作题目中的指令,从原点移动到目标点。
分析:如果一次完毕全部的命令后。移动到了(xx,yy),而且从(Xi。Yi)反复操作k次指令到达目标点。则能够列出方程 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;
}
CodeForces 321A Ciel and Robot(数学模拟)的更多相关文章
- Codeforces Round 190 div.2 322C 321A Ciel and Robot
唔...这题是数学题. 比赛时做出来,但题意理解错了,以为只要判断那点是不是在线上就行了,发现过不了样例就没提交. 思路:记录每一步的偏移,假设那点是在路径上的某步,然后回推出那一个周期的第一步,判断 ...
- CodeForces 321A
A. Ciel and Robot time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Ciel and Robot
C. Ciel and Robot time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces G. Ciel the Commander
题目描述: Ciel the Commander time limit per test 1 second memory limit per test 256 megabytes input stan ...
- CodeForces 321 A - Ciel and Robot
[题目链接]:click here~~ [题目大意]:一个robot 机器人 .能够依据给定的指令行动,给你四种指令,robot初始位置是(0,0).指令一出.robot会反复行动,推断是否能在无限行 ...
- Codeforces Round #115 A. Robot Bicorn Attack 暴力
A. Robot Bicorn Attack Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/17 ...
- CodeForces 321C Ciel the Commander
Ciel the Commander Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForc ...
- Codeforces 321E Ciel and Gondolas
传送门:http://codeforces.com/problemset/problem/321/E [题解] 首先有一个$O(n^2k)$的dp. # include <stdio.h> ...
- Codeforces 321D Ciel and Flipboard(结论题+枚举)
题目链接 Ciel and Flipboard 题意 给出一个$n*n$的正方形,每个格子里有一个数,每次可以将一个大小为$x*x$的子正方形翻转 翻转的意义为该区域里的数都变成原来的相反数. ...
随机推荐
- ASP.NET使用Memcached高缓存实例的初级介绍
Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提供动态.数据库驱动网站的速度.Memcached ...
- Python GUI界面开发环境配置:Pycharm+PyQt5
通过DoS命令行执行如下命令,可能需要管理员权限. 检查Python版本:python 更新pip版本:python -m pip install --upgrade pip 安装PyQt5: pip ...
- Django 连接mysql数据库
首先在settings.py文件里将 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.pat ...
- rootfs注册挂载过程分析
参考:Linux Filesystem: 解析 Linux 中的 VFS 文件系统机制 主要代码, init_rootfs(); init_mount_tree(); 1.init_rootfs()解 ...
- timer event
/* linux/kernel/time/jiffies.c*/ static cycle_t jiffies_read(struct clocksource *cs) { return (cycle ...
- JavaScript正则表达式-定义
通过RegExp()构造函数创建RegExp对象来定义正则表达式. var reg_pattern = new RegExt("a\d"); 通过字面语法直接定义正则表达式. va ...
- Linux下安装SaltStack
一.配置yum源和epel源 epel源下载地址:http://pan.baidu.com/s/1o7NJ26u 1.配置yum源 (1)上传操作系统镜像文件来配置yum源,挂载点目录为/yum mk ...
- iptables防火墙简介
原文地址:http://drops.wooyun.org/tips/1424 一.iptables介绍 linux的包过滤功能,即linux防火墙,它由netfilter 和 iptables 两个组 ...
- 学习shell脚本之乘法口诀
脚本如下: #!/bin/bash for i in 'seq 1 9' do for j in 'seq 1 $i' do k=$[$i*$j] echo -ne "$j"&qu ...
- 最长递增子序列(cogs 731)
«问题描述:给定正整数序列x1,..., xn.(1)计算其最长递增子序列的长度s.(2)计算从给定的序列中最多可取出多少个长度为s的递增子序列.(3)如果允许在取出的序列中多次使用x1和xn,则从给 ...