4A - Horse
打表找规律
#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的更多相关文章
- 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 ...
- 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 ...
- HDUOJ-------1052Tian Ji -- The Horse Racing(田忌赛马)
Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- 【策略】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 ...
- Tian Ji -- The Horse Racing
Tian Ji -- The Horse Racing Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Jav ...
- 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 ...
- hdoj 1052 Tian Ji -- The Horse Racing【田忌赛马】 【贪心】
思路:先按从小到大排序, 然后从最快的開始比(如果i, j 是最慢的一端, flag1, flag2是最快的一端 ),田的最快的大于king的 则比較,如果等于然后推断,有三种情况: 一:大于则比較, ...
- Tian Ji -- The Horse Racin
Tian Ji -- The Horse Racin Problem Description Here is a famous story in Chinese history. "That ...
- hdu1052 Tian Ji -- The Horse Racing 馋
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1052">http://acm.hdu.edu.cn/showproblem.php ...
随机推荐
- nodejs npm install -g 全局安装和非全局安装的区别
1. npm install xxx -g 时, 模块将被下载安装到[全局目录]中. [全局目录]通过 npm config set prefix "目录路径" 来设置. 比如说, ...
- Bootstrap 简介(Web前端CSS框架)
目录1.简介2.特点3.组件4.Javascript插件5.定制自己的框架代码6.Bootstrap Less 1.简介Bootstrap是Twitter推出的一个开源的用于前端开发的工具包.它由Tw ...
- codeforce452DIV2——E. Segments Removal
题目 Vasya has an array of integers of length n. Vasya performs the following operations on the array: ...
- Composert 的命令
(1) php artisan ----查看所有的命令帮助 (2) php artisan make:controller StudentController ----创建一个控 ...
- jps, jinfo命令
jps主要用来输出JVM中运行的进程状态信息. -q 不输出类名.Jar名和传入main方法的参数 -m 输出传入main方法的参数 -l 输出main类或Jar的全限名 -v 输出传入JVM的参数 ...
- 基于PCL的屏幕选点、框选点云、单点选取
1. 单点选取 #include <pcl/io/pcd_io.h> #include <pcl/point_cloud.h> #include <pcl/point_t ...
- ubuntu 环境变量设置
一:用于当前终端:在当前终端中输入:export PATH=$PATH:<你的要加入的路径>不过上面的方法只适用于当前终端,一旦当前终端关闭或在另一个终端中,则无效.export NDK_ ...
- Asp.NET中把DataTable导出为Excel ,中文有乱码现象解决办法
//DataTable为要导出的数据表 DataGrid dg = new DataGrid(); dg.DataSource = DataTable; ...
- Java IO RandomAccessFile 任意位置读/写
随机读写类 RandomAccessFile的唯一父类是Object,与其他流父类不同.是用来访问那些保存数据记录的文件的,这样你就可以用seek( )方法来访问记录,并进行读写了.这些记录的大小不必 ...
- .net 特性 Attribute
public sealed class RemarkAttribute : Attribute { public string Remark { get; set; } // 构造函数 public ...