[Zhengqing] [1757] Wrz and Latiao

Problem Description

Loading...

Problem Analysis

At first glance I had no idea
A second glance and it seems to have nothing to do with graphs
Think again and it feels pretty simple
Write it out…
WA’d -.-

At the time I didn’t notice this sentence:

He can choose to teleport to the 1st pillar or the nth pillar at any position

I thought it meant teleporting to any pillar…
Then I had to look for the pattern all over again…

By the way, isn’t this somewhat similar to
the BFS I’m reading about right now…

So I won’t analyze the problem…
Just look at the code~
Discuss it case by case

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<stdio.h>
int main() {
	int n,s,t,x;
	while(scanf("%d %d %d",&n,&s,&t)!=EOF) {
		x=0;
		if(s==t) {
			x=-1;
			if(n==1)
				x=0;
		} else {
			if((s==1&&t==n)||(s==n&&t==1))
				x=0;
			else if(s-t==1||s-t==-1) {
				x=1;
				if((s==1&&t!=2)||(s==n&&t!=n-1))
					x=0;
			} else {
				x=2;
				if(s==1||s==n)
					x=1;
			}
		}
		printf("%d\n",x);
	}
	return 0;
}
This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...