首页 > 其他分享 >CF141B Hopscotch 题解

CF141B Hopscotch 题解

时间:2024-07-16 16:00:02浏览次数:14  
标签:正方体 输出 stone square return Hopscotch 题解 样例 CF141B

Hopscotch

题面翻译

有 n n n 个形状和大小都一致的正方体积木,积木堆积的样式是第一层只有一个正方体,然后上面就开始循环了,循环体为:第一层是一个正方体,第二层是两个正方体。如下图所示:

现在给你三个数 a , x , y a,x,y a,x,y 表示正方体的边长,然后让你输出坐标 ( x , y ) (x,y) (x,y) 对应的数。如果在积木的边界上或者是不在正方体上输出 − 1 -1 −1。

题目描述

So nearly half of the winter is over and Maria is dreaming about summer. She’s fed up with skates and sleds, she was dreaming about Hopscotch all night long. It’s a very popular children’s game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks in the same row are numbered from left to right). Let us describe the hopscotch with numbers that denote the number of squares in the row, staring from the lowest one: 1-1-2-1-2-1-2-(1-2)…, where then the period is repeated (1-2).

The coordinate system is defined as shown in the figure. Side of all the squares are equal and have length $ a $ .

Maria is a very smart and clever girl, and she is concerned with quite serious issues: if she throws a stone into a point with coordinates $ (x,y) $ , then will she hit some square? If the answer is positive, you are also required to determine the number of the square.

It is believed that the stone has fallen into the square if it is located strictly inside it. In other words a stone that has fallen on the square border is not considered a to hit a square.

输入格式

The only input line contains three integers: $ a $ , $ x $ , $ y $ , where $ a $ ( $ 1<=a<=100 $ ) is the side of the square, $ x $ and $ y $ ( $ -10{6}<=x<=10{6},0<=y<=10^{6} $ ) are coordinates of the stone.

输出格式

Print the number of the square, inside which the stone fell. If the stone is on a border of some stone or outside the court, print “-1” without the quotes.

样例 #1

样例输入 #1

1 0 0

样例输出 #1

-1

样例 #2

样例输入 #2

3 1 1

样例输出 #2

1

样例 #3

样例输入 #3

3 0 10

样例输出 #3

5

样例 #4

样例输入 #4

3 0 7

样例输出 #4

-1

样例 #5

样例输入 #5

3 4 0

样例输出 #5

-1
#include<iostream>
using namespace std;
int a,x,y;//定义三个正整数,一个叫a……
int _main(){
	if(y%a==0)return-1;
	if(y<0)return-1;
	if(abs(x)>=a)return-1;
	//以上为一开始讨论的三种不可能情况
	int c=y/a;
	if(c==0||c%2){
		if(abs(2*x)>=a)return-1;
		else return max(1,(c+1)/2*3-1);
	}
	//以上为第0层或者奇数层的情况
	if(c&&c%2==0){
		if(x==0)return-1;
		else return c/2*3+(x+a)/a;
	}
	//以上为非零偶数层的情况
}
int main(){
	cin>>a>>x>>y;
	cout<<_main();
}

标签:正方体,输出,stone,square,return,Hopscotch,题解,样例,CF141B
From: https://blog.csdn.net/yaosichengalpha/article/details/140456190

相关文章

  • AT_dp_a Frog 1 题解
    Frog1题面翻译NNN个石头,编号为1,2......
  • 【题解】AT_abc192_d [ABC192D] Base n
    洛谷AT_abc192_d题解\(66pts\)其实我也不知道为什么考场上会想出dfs这种做法(严格来说应该不算),但是最后的分数还是比较可观的。主要思路首先,将\(X\)视为一个\(n\)进制数\(X'\)。枚举\(n\)进制,从字符串\(X\)中的最大数字加\(1\)开始。在此过程中,如果\(X'\)比......
  • [题解]POJ3304 Segment
    POJ3304Segment题意简述多测,每次给定\(n\)条线段,请问是否能找到\(1\)条直线,使得所有线段在该直线上的投影有公共部分。注:两点距离\(<10^{-8}\)被认为是相等的。思路分析题意转化一下,就是要我们找一条直线\(l_1\),穿过所有线段。这样对于任意直线\(l_2\perpl_1\),都满足题意。......
  • [题解]UVA10902 Pick-up Sticks
    题意简述多测。给定坐标系上依次给定\(n\)根木棍的起始和终止坐标,按顺序放置这些木棍,询问最终处在最上层的木棍有哪些。\(n\le100000\)。保证任意时刻最上层的木棍不超过\(1000\)个。思路分析看起来数据范围很刁钻,不过除了暴力以外的方法想不出了,就写了一份上交,结果过了。思......
  • 题解:P10724 [GESP202406 七级] 区间乘积
    思路看到\(a_i\)很小,不难想到状压一类的东西。考虑把每个数的质因数当做二进制位,这个二进制位的\(1/0\)代表含有这个质因数的奇偶,再做一个异或前缀和,显然完全平方数的质因子个数一定为偶数,根据异或的性质,两个相同的数异或才为\(0\)所以只需要找到异或前缀和中相同的数的个......
  • 迷宫守卫 题解
    给个题目链接:迷宫守卫。下面直接开始讲了。发现一个事情,省选的题已经不怎么考板子难度很高的题了,现在考的都是思维难度非常高的题。首先,我们考虑字典序的性质,如果第一位劣,那么后面无论多优都没用,所以我们要优先满足靠前的位置。于是我们考虑使用二分来找出第一个数,后面以此类......
  • 题解:SP11469 SUBSET - Balanced Cow Subsets
    SP11469(折半搜索)题目大意:给出$N$个数,求可以被分成两个和相等的集合的子集数。思路分析:首先考虑朴素的DFS,每个数有三种情况:选为$A$集合,选为$B$集合,两个集合都不选。暴力DFS时间复杂度为$3^{20}$。观察到$N$很小,而$3^{10}$是可以通过本题的,于是考虑折半搜索。我......
  • P10720 [GESP202406 五级] 小杨的幸运数字 题解
    题意如果一个数的质因子中只有两个不同的数则输出\(1\),否则输出\(0\)。思路从第一个质因子遍历到\(sum\)的话很明显是\(O(nt)\)最大是\(n^{10}\)很明显会炸掉。所以遍历到\(sum\)是不行的,考虑正整数\(n\)最大的质因数是\(\sqrt{n}\)所以遍历到\(\sqrt{n}\)即......
  • 题解:SP10502 VIDEO - Video game combos
    大意构造一个长度为\(k\)(\(k\)是给定的)的串\(x\),使得对于\(∀1\leqi\leqn,s_i\)在\(x\)中的出现次数之和最大。输出这个最大值。思考考虑对\(s_i\)建AC自动机,然后dp。记\(dp[i][u]\)表示为长度为\(i\)的字符串,且当前已计算的节点是Trie上的编号为\(u......
  • 【题解】 [CSP-J 2021 T1] 分糖果
    题目描述题目大意给定正整数\(n\)、\(L\)、\(R\),求\(\max_{i\in\left[L,R\right]}{i\bmodn}\)。思路题目主要考察:分类讨论。众所周知,对于\(\forallx\),有$(x\bmodn)\in\left[0,n-1\right]$。可以分为两种情况讨论:如果\(\left\lfloor\frac{L......