打表找规律

#include <iostream>
#include <queue>
using namespace std;
bool vis[][];
int dx[]{, , , , -, -, -, -};
int dy[]{, -, , -, , -, -, };
struct point
{
int x;
int y;
int deep;
};
queue<point> q; int bfs(int n)
{
while (!q.empty())
q.pop();
memset(vis, false, sizeof(vis));
point head;
head.x = head.y = ;
head.deep = ;
q.push(head);
vis[head.x][head.y] = true; int sum = ;
while (!q.empty()) {
head = q.front();
q.pop();
point np;
for (int i = ; i < ; i++) {
np.x = head.x + dx[i];
np.y = head.y + dy[i];
np.deep = head.deep + ;
if (np.x >= && np.x <= && np.y >= && np.y <= && !vis[np.x][np.y] && np.deep <= n) {
vis[np.x][np.y] = true;
q.push(np);
sum++;
}
}
}
return sum;
} int main()
{
ios::sync_with_stdio(false);
cin.tie(); int arr[];
for (int i = ; i <= ; i++) {
arr[i] = bfs(i);
cout << arr[i] << ' ';
}
cout << endl;
int b[];
int k = ;
for (int i = ; i <= ; i++) {
b[k] = arr[i] - arr[i - ];
cout << b[k++] << ' ';
}
cout << endl;
for (int i = ; i < k; i++)
cout << b[i] - b[i - ] << ' ';
cout << endl;
return ;
}

打表发现第五项205开始,后一项减前一项的差值(第二排),再与之后的差值做差值,值都是28.

最终结果:

#include <iostream>
using namespace std;
typedef unsigned long long ull;
int arr[] {, , , , }; int main()
{
ios::sync_with_stdio(false);
cin.tie();
int t;
cin >> t;
while (t--) {
ull n;
cin >> n;
if (n < )
cout << arr[n] << endl;
else {
ull diff = n - ;
cout << + diff * + (diff - ) * diff * << endl;
}
}
return ;
}

4A - Horse的更多相关文章

  1. Hdu 1052 Tian Ji -- The Horse Racing

    Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  2. HDU 1052 Tian Ji -- The Horse Racing(贪心)(2004 Asia Regional Shanghai)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 Problem Description Here is a famous story in Ch ...

  3. HDUOJ-------1052Tian Ji -- The Horse Racing(田忌赛马)

    Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  4. 【策略】UVa 1344 - Tian Ji -- The Horse Racing(田忌赛马)

    Here is a famous story in Chinese history. That was about 2300 years ago. General Tian Ji was a high ...

  5. Tian Ji -- The Horse Racing

    Tian Ji -- The Horse Racing Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Jav ...

  6. UVA 1344 Tian Ji -- The Horse Racing

    Tian Ji -- The Horse Racing Here is a famous story in Chinese history. That was about 2300 years ago ...

  7. hdoj 1052 Tian Ji -- The Horse Racing【田忌赛马】 【贪心】

    思路:先按从小到大排序, 然后从最快的開始比(如果i, j 是最慢的一端, flag1, flag2是最快的一端 ),田的最快的大于king的 则比較,如果等于然后推断,有三种情况: 一:大于则比較, ...

  8. Tian Ji -- The Horse Racin

    Tian Ji -- The Horse Racin Problem Description Here is a famous story in Chinese history. "That ...

  9. hdu1052 Tian Ji -- The Horse Racing 馋

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1052">http://acm.hdu.edu.cn/showproblem.php ...

随机推荐

  1. js控制图片放大缩小的简易版

    js代码: function bb_img_onmousewheel(e, o) { var zoom = parseInt(o.style.zoom, 10) || 100; zoom += eve ...

  2. js的简单介绍及基本用法

    1. JS的简介 概述: JavaScript, 是一门弱类型语言, 用来给页面增加动态功能的. //弱类型语言: 对数据的数据类型划分不精细(不明确). 特点: A. JavaScript 是一种轻 ...

  3. php 实现百度文库搭建

    第一步:安装jodconverter,安装之后可以实现doc文档转成pdf. 文件下载地址为http://www.artofsolving.com/opensource/jodconverter 下载 ...

  4. 2014蓝桥杯B组初赛试题《切面条》

    题目描述: 一根高筋拉面,中间切一刀,可以得到2根面条.     如果先对折1次,中间切一刀,可以得到3根面条.     如果连续对折2次,中间切一刀,可以得到5根面条.     那么,连续对折10次 ...

  5. servlet01 项目demo、servlet生命周期

    1 环境说明 jdk: 1.8 tomcat: 8.0 2 项目demo 2.1 新建一个动态的web项目   2.2 新建一个servlet类 该类必须继承 HttpServlet 技巧01:Htt ...

  6. shell动态替换变量

    可以对env指定U 或者 L,  得到U或者L下的IP地址列表, env可作为shell的参数列表传入 env=UL_ips=(x.x.x.x  y.y.y.y)U_ips=(w.w.w.w  z.z ...

  7. Python PyPI中国镜像

    from:http://blog.makto.me/post/2012-11-01/pypi-mirror from:http://www.pypi-mirrors.org/ from:http:// ...

  8. 13-STL-二分查找

    STL中提供-二分查找算法(binary_search lower_bound upper_bound equal_range   STL包含四种不同的二分查找算法,binary_search    ...

  9. jQuery基础教程-第8章-002Adding jQuery object methods

    一.Object method context 1.We have seen that adding global functions requires extending the jQuery ob ...

  10. Luogu 3594 [POI2015]WIL-Wilcze doły

    简单题. 考虑没有修改数字的条件的限制,我们直接用双指针扫描就可以计算出答案了. 然后考虑加入修改数字的条件,只要用单调队列维护出当前两个指针表示的区间中长度为$d$的一段区间的最大值,用总和减掉这个 ...