打表找规律

#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. express源码学习

    终于腾出手来学习express.express在node.js中一株独秀.好像任何一种有主导的托管平台的语言,都出现这现象--马太效应.express是社区的共同孩子,里面聚集上社区最好的常用模块.从 ...

  2. Linux的基本指令--其他命令

    一 . 终端翻页: shift-pageup shift-pagedown 二 . 看手册:man man man 2 read 查看read系统函数的man page(在第二个section中,表示 ...

  3. Java,Calendar -- 获取当前日期、当月月初日期、月末日期

    public class CalendarTest { public static void main(String[] args) { // 获取当前年份.月份.日期 Calendar cale = ...

  4. 面向对象property属性、静态方法和类方法

    一.property属性 1.什么是property特性? property是一种特殊的属性,访问它时会执行一段功能(函数)然后返回值. from math import pi class Circl ...

  5. cbv+resful+APIView源码分析

    CBV源码分析 1概念:什么是cbv和fbv 已经什么是API class bass View ---基于类的视图 function bass View ---基于函数的视图 API(Applicat ...

  6. Unity破解不成功解决方案

    你是不是遇到过Unity新版本出来的时候就急着使用,但是安装好了,却破解不成功的问题(你之前的版本破解过).这是由于你的注册表没有彻底的删除,接下来我们图解如何清理. 1.卸载以前的版本,卸载完了删除 ...

  7. py_initialize:C调Python出错 是初始化错误?

    还是pythonpath和pythonname变量没有配置正确? py_initialize()方法是什么? In an application embedding Python, this shou ...

  8. Ubuntu 16.04 安装jdk

    Ubuntu 16.04 安装jdk 准备工作 安装版本:jdk-8u91-linux-x64.tar.gz 官方下载 创建目录作为JDK的安装目录,这里选择安装位置为:/usr/java/ sudo ...

  9. POJ3020 Antenna Placement(二分图最小路径覆盖)

    The Global Aerial Research Centre has been allotted the task of building the fifth generation of mob ...

  10. ORB SLAM2 学习笔记

    cd ~/Documents/demos/ORB_SLAM2 ./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUM1.y ...