[ACM] 1007 -球球方格

与兔子方格类似,不过一秒走一格;

输入


代码

#include<iostream>
using namespace std; int main(void) {
int test_count;
freopen("input.txt", "r", stdin);
cin >> test_count; int R;//行数
int C;//列数
int A, B;//出发点坐标
int N;//经过时间
int flagA;
int flagB;
for (int test_case = ; test_case <= test_count; test_case++)
{
cin >> R >> C >> A >> B >> N;
flagA = ;//默认开始每个例子都是向右下角移动
flagB = ; while (N>)
{
if (A != R - ) {
if(flagA == )
{
A++;
if (A == R - )
{
flagA = -; }
else
{
flagA = ; }
}
else
{
A--;
if (A == ) {
flagA = ; }
else
{
flagA = -; }
} } else
{
if (flagA == -)
{
A--;
if (A == ) {
flagA = ; }
else
{
flagA = -; }
}
else
{
A++;
if (A == R - ) {
flagA = -;
}
else
{
flagA = ; }
} } if (B != C - ) {
if (flagB == )
{
B++;
if (B == C - )
{
flagB = -; }
else
{
flagB = ; }
}
else
{
B--;
if (B == ) {
flagB = ; }
else
{
flagB = -; }
} } else
{
if (flagB == -)
{
B--;
if (B == ) {
flagB = ; }
else
{
flagB = -; }
}
else
{
B++;
if (B == C - ) {
flagB = -; }
else
{
flagB = ; }
} }
N--;
} cout << "#" << test_case << " " << A << " " << B << endl;
} return ;
}
上一篇:HDU2227Find the nondecreasing subsequences(树状数组+DP)


下一篇:POJ 3831 & HDU 3264 Open-air shopping malls(几何)