NBUT 1224 Happiness Hotel 2010辽宁省赛
Time limit 1000 ms
Memory limit 131072 kB
The life of Little A is good, and, he managed to get enough money to run a hotel. The best for him is that he need not go to work outside, just wait for the money to go into his pocket. Little A wants everything to be perfect, he has a wonderful plan that he will keep one most beautiful reception whose size is 1()(which means the reception is 1 square meter). There are other k rooms that have the same area, and the area is x^2(), x is an integer; Little A wants his hotel to be a square. Little A is a good thinker, but not a good maker. As his poor performance on math, he cannot calculate the least area needed to build such a hotel of his will. Now, this task belongs to you, solve this problem to make Little A’s dream of Happy Hotel come true. Please be careful, the whole area should only contain k rooms, and the reception, there should not be any vacant place.
Input
Each case contains only one integer k(1<=k<=1000) ,the number of rooms the hotel should have in one line.
Proceed to the end of file.
Output
Sample Input
1
2
3
Sample Output
no solution
3
2 要求n*a*a+1=b*b,a,b都是整数,n<=1000,看有没有这样的a,b 网上copy的代码。。还没理解还没自己写。。先记着
来自http://blog.sina.com.cn/s/blog_7e9a88f70100sot1.html
#include <iostream>
#include <cmath>
using namespace std; int can[];
int a[][];
int x[],y[],t[];
int h1,h2;
int bb,ee,xx,yx,c,n; void gui(int ji,int many,int ma,int kk)
{
if (ji<kk)
gui(ji+,a[ma][(ji-)%a[ma][]+],ma,kk);
else
{
h1=;
h2=;
x[]=many;
y[]=;
return;
}
for (int i=;i<=h1;i++)
t[i]=x[i];
for (int i=;i<=h2;i++)
x[i]=y[i];
for (int i=;i<=h1;i++)
y[i]=t[i];
c=h1;
h1=h2;
h2=c;
for (int i=;i<=h2;i++)
{
if (i<=h1)
x[i]+=many*y[i];
else
x[i]=many*y[i];
}
if (h2>h1)
h1=h2;
for (int i=;i<h1;i++)
{
if (x[i]>=)
{
x[i+]+=x[i]/;
x[i]%=;
}
}
while (x[h1]>=)
{
x[h1+]=x[h1]/;
x[h1]%=;
h1++;
}
x[]=h1;
} int main()
{ for (int i=;i<=;i++)
can[i*i]=true;
for (int i=;i<=;i++)
if (!can[i])
{
a[i][]=;
bb=;
ee=(int)sqrt((double)i);
a[i][]=ee;
ee=-ee;
xx=bb;
yx=ee;
xx=-yx;
yx=i-yx*yx;
n=;
while ((xx-yx)*(xx-yx)<i||xx>=)
{
xx-=yx;
n++;
}
a[i][]=n;
c=xx;
xx=yx;
yx=c;
while (xx!=bb||yx!=ee)
{
a[i][]++;
c=xx;
xx=-yx;
yx=i-yx*yx;
yx=yx/c;
n=;
while ((xx-yx)*(xx-yx)<i||xx>=)
{
xx-=yx;
n++;
}
a[i][a[i][]]=n;
c=xx;
xx=yx;
yx=c;
}
}
int i;
while (scanf("%d",&i)!=EOF)
{
if (!can[i])
{
if (a[i][]%)
gui(,a[i][],i,a[i][]*);
else
gui(,a[i][],i,a[i][]);
for (int j=x[];j>=;j--)
printf("%d",x[j]);
printf("\n");
}
else
printf("no solution\n");
}
return ;
}
NBUT 1224 Happiness Hotel 2010辽宁省赛的更多相关文章
- NBUT 1222 English Game 2010辽宁省赛
		Time limit 1000 ms Memory limit 131072 kB This English game is a simple English words connection gam ... 
- NBUT 1223 Friends number 2010辽宁省赛
		Time limit 1000 ms Memory limit 131072 kB Paula and Tai are couple. There are many stories betwee ... 
- [NBUT 1224 Happiness Hotel 佩尔方程最小正整数解]连分数法解Pell方程
		题意:求方程x2-Dy2=1的最小正整数解 思路:用连分数法解佩尔方程,关键是找出√d的连分数表示的循环节.具体过程参见:http://m.blog.csdn.net/blog/wh2124335/8 ... 
- NBUT 1221 Intermediary  2010辽宁省赛
		Time limit 1000 ms Memory limit 131072 kB It is widely known that any two strangers can get to know ... 
- NBUT 1225 NEW RDSP MODE I  2010辽宁省赛
		Time limit 1000 ms Memory limit 131072 kB Little A has became fascinated with the game Dota recent ... 
- NBUT 1218 You are my brother  2010辽宁省赛
		Time limit 1000 ms Memory limit 131072 kB Little A gets to know a new friend, Little B, recently. On ... 
- NBUT 1220 SPY 2010辽宁省赛
		Time limit 1000 ms Memory limit 131072 kB The National Intelligence Council of X Nation receives a ... 
- NBUT 1219 Time 2010辽宁省赛
		Time limit 1000 ms Memory limit 131072 kB Digital clock use 4 digits to express time, each digit ... 
- NBUT 1217 Dinner 2010辽宁省赛
		Time limit 1000 ms Memory limit 32768 kB Little A is one member of ACM team. He had just won the g ... 
随机推荐
- Linux——软件包简单学习笔记
			Linux中的是那种软件包: (这里学习是基于redHat的Cent-OS) 1: 二进制软件包管理(RPM.YUM) 2:源代码包安装 3: 脚本安装(Shell或Java脚本) 一: 二进制软件 ... 
- Remastersys -- 将正在使用的Ubuntu14.04 制作成镜像文件
			remastersys 是一个能够备份你的ubuntu系统的工具. 源码在github上能找到:Remastersys Source 另外系统是 Ubuntu14.04/12.04 也可以直接 apt ... 
- ubuntu 16.04 kinetic 安装rosbridge
			sudo apt-get install ros-kinetic-rosbridge-server 
- JavaScript 基础知识入门
			 js3种弹出框 alert消息对话框 var mychar=I love JavaScript;alert(mychar); confirm消息对话框 返回值:bool var mymessage ... 
- jq 命名空间
			$('ul').on("click",function(){console.log('all');});$('ul').on("click.a",functio ... 
- 时间常用api
			1.常用api 创建 Date 对象 - 年 - 月 - 日 - 小时 - 分 - 秒 - 星期 var now=new Date() var year = now.get ... 
- Python 爬虫-正则表达式
			2017-07-27 13:52:08 一.正则表达式的概念 (1)正则表达式是用来简洁表达一组字符串的表达式,最主要应用在字符串匹配中. 正则表达式是用来简洁表达一组字符串的表达式 正则表达式是一 ... 
- 013 - 关于GC root: Native Stack  |  MAT分析
			Question: I have some third library code that I run and after some time I run into OutOfMemoryEr ... 
- Objections vs. excuses
			Objections are healthy. When someone is being offered a new opportunity or product, it's not unusual ... 
- Android之SwipeRefreshLayout下拉刷新组件
			SwipeRefreshLayout概述 SwipeRefrshLayout是Google官方更新的一个Widget,可以实现下拉刷新的效果.该控件集成自ViewGroup在support-v4兼容包 ... 
