打表找规律

#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. DLL卸载

    [DLL卸载] 1.扫描Module.通过CreateToohelp32Snapshot.Module32First.Module32Next来完成. 2.通过FreeLibrary来卸载.通过在ke ...

  2. 设置html页面不被浏览器缓存

    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" ...

  3. Linux 下Nginx 运行Vue

    首相基础的安装Node.js  npm 先建个目录把 /node/www 然后在这个目录下 wget https://nodejs.org/dist/v8.11.1/node-v8.11.1-linu ...

  4. Linux 安装lamp

    安装软件包编译器 gcc -v 查看是否存在 yum -y install gcc gcc-c++ mack rpm -q httpd 查看是否安装http rpm -e httpd --nodeps ...

  5. JSP页面使用EL表达式出现的问题:javax.el.PropertyNotFoundException: Property 'ID' not found on type java.lang.Str

    问题描述: 1. 后台返回到JSP前台的的list,在jsp页面使用EL表达式遍历时出现如下问题:javax.el.PropertyNotFoundException: Property 'ID' n ...

  6. solr第二天 京东案例 课程文档 有用

    全文检索技术   Lucene&Solr               Part3 1. 课程计划 1. Solr配置中文分析器 a) Schema.xml的配置 b) 配置IKAnalyzer ...

  7. centos 安装mongodb3.0

    一.添加yum源 vi /etc/yum.repos.d/mongodb-org-3.0.repo 请添加如下配置(64位系统): [mongodb-org-3.0] name=MongoDB Rep ...

  8. c# 常规验证基类

    using System;using System.Collections.Generic;using System.Linq;using System.Text.RegularExpressions ...

  9. mvc全局过滤器和httpmodule的执行顺序

    根据http管线模型,请求先通过httpmodule,再通过httphandler,之后再进入mvc的过滤器 另外参考:MVC如何在Pipeline中接管请求的? http://www.cnblogs ...

  10. Request[]与Request.Params[] 差别

    Request[]与Request.Params[] ,这二个属性都可以让我们方便地根据一个KEY去[同时搜索]QueryString.Form.Cookies 或 ServerVariables这4 ...