Day16 洛谷真题讲解

呀呀呀呀,嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻,太开心了,终于看到了一丝丝快乐的光环,终于ac了

 Day16 洛谷真题讲解_第1张图片

大家先来看一眼这道题,我觉得其实还是真的蛮经典的,刚开始的时候我心思看看如何能够把每个数给他存进一个数组里面,后来我发现原来,这个题目,只要在深深的探查一下,就会慢慢发现其中的道理,于是我重新开始想方法,okl,终于找到了一个这个

Day16 洛谷真题讲解_第2张图片 

好个找规律,我真觉得这个普及-的题,好像每一道都有点找规律。

大家仔细看我上面的那个演草纸一定能够发现的 

#include
#include
#include
using namespace std;
int main()
{
	int x;
	cin >> x;
	double limit = ((-1) + sqrt(1 - 4 * (-2*x))) / 2;
	int limit2 = (int)(((-1) + sqrt(1 - 4 * (-2*x))) / 2);
	if (limit > limit2)
	{
		int lim = limit2 + 1;
		int m = x - limit2 * (limit2 + 1) / 2;//这个代表的是第几个数
		if (lim % 2 != 0)
		{
			
			cout << lim - m +1<< "/" << 1 + m-1;
		}
		else
		{
			cout << 1 + m-1 << "/" << lim - m+1;
		}
	}
	else if(limit==limit2)
	{
		if (limit2 % 2 != 0)
		{
			cout << 1 << "/" << limit2;
		}
		else
		{
			cout << limit2 << "/" << 1;
		}
	}


}

你可能感兴趣的:(c++,算法,开发语言)