大一集训题i题生日聚会lightoj-1008 - Fibsieve`s Fantabulous Birthday

大一集训题i题生日聚会lightoj-1008 - Fibsieve`s Fantabulous Birthday

**大一集训题i题生日聚会lightoj-1008 - Fibsieves Fantabulous Birthday**## 大一集训题i题生日聚会lightoj-1008 - Fibsieves Fantabulous Birthday
Fibsieve had a fantabulous (yes, it’s an actual word) birthday party this year. He had so many gifts that he was actually thinking of not having a party next year.

Among these gifts there was an N x N glass chessboard that had a light in each of its cells. When the board was turned on a distinct cell would light up every second, and then go dark.

The cells would light up in the sequence shown in the diagram. Each cell is marked with the second in which it would light up.

(The numbers in the grids stand for the time when the corresponding cell lights up)

In the first second the light at cell (1, 1) would be on. And in the 5th second the cell (3, 1) would be on. Now, Fibsieve is trying to predict which cell will light up at a certain time (given in seconds). Assume that N is large enough.

Input starts with an integer T (≤ 200), denoting the number of test cases.
Each case will contain an integer S (1 ≤ S ≤ 1015) which stands for the time.
翻译:
F要开幻想生日聚会(是的,这是个实际的词今年,
他想收到很多礼物,也就是想把接下来几年的都收了。(太sb了,真是今朝有酒今朝醉->o<)
接下来有nxn的装有LED灯的玻璃盒子,‎玻璃棋盘,每个小室内都有一盏灯。‎‎当板打开一个独特的小室将照亮每一秒,然后变暗。‎
‎单元格将按图中显示的顺序点亮。每个单元格都标有第二个单元格,其中将点亮。‎
这个第一个盒子在(1,1)的位置上,第五个在(3,1)位子上。假设有nxn个盒子。巴拉巴拉。。。

大意:Fibisieve生日聚会需要彩灯,彩灯按照指定规律排放。
规律如下:
25 24 23 22 21
10 11 12 13 20
9 8 7 14 19
2 3 6 15 18
1 4 5 16 17
我的思路:
将每不同颜色的彩灯放成一排,最后排成如三角形的样子,如:
(1,1)
(1,2)(2,2)(2,1)
(3,1)(3,2)(3,3)(2,3)(1,3)

分别代表:
1
2 3 4
5 6 7 8 9

如此会发现每一组最后一个数都是改行的平方;
且每组的中间值都是其行数的两个值(i,i),称为其拐点;
我的代码:

#include"stdio.h"
#include<math.h>
#include<string.h> 
int main()
{
	int n,copy;
	scanf("%d",&n);
	copy=n;
	while(n--){
		long long int a,b,i,c,d;
		scanf("%lld",&a);
		if(a==1)printf("Case %d: 1 1\n",copy-n);
		else if(a==2)printf("Case %d: 1 2\n",copy-n);
		else{
			i=ceil(sqrt(a));
			b=ceil((pow(i,2)+pow(i-1,2))/2.0);
			c=pow(i,2);
			d=pow(i-1,2);
			if(a!=i*i){
				if(i&1){
					if(a<b) printf("Case %d: %lld %lld\n",copy-n,a-d,i);
					else printf("Case %d: %lld %lld\n",copy-n,i,c-a+1);
				}
				else {
					if(a<b) printf("Case %d: %lld %lld\n",copy-n,i,a-d);
					else printf("Case %d: %lld %lld\n",copy-n,c-a+1,i);
				}
			} 
			
			else if(a==i*i){
				if(i&1){printf("Case %d: 1 %lld\n",copy-n,i);}
				else {printf("Case %d: %lld 1\n",copy-n,i);}
			}
		}
	}return 0;
}//核心思想;将每组列成有规律的三角型类型,如
//(1,1)
//(1,2)(2,2)(2,1)
//(3,1)(3,2)(3,3)(2,3)(1,3)
//...... 
//题后感想; 
//******题目不难想,属于偏难,但不至于写不出,如下是我写时出现的问题;
//1.该注意的是奇数行和偶数行的规律是反的。
//2.每组都有拐点(i,i)。
//3.ceil函数运用。
//4.输入的值可以通过根号查到在哪行。
//5.每组最后的值都是(1,i^2)or(i^2,1)形式。 

这是我之后改动的
题后反思:在代码注释中。
拓展:
其实就是一个找规律的题目,规律简单。所有找规律的题基本上都差不多。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值