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 ...
随机推荐
- 继承ServletContextListener可以完成的事情
1.定时任务: 定时任务是从某个固定的时间开始执行特定的程序,继承这个方法,可以实现刚启动项目的时候执行某特定的程序,完成给客户部署的时即可以看到某个页面的效果. 2.初始化系统常量等: 这样来完成系 ...
- nodejs npm install -g 全局安装和非全局安装的区别
1. npm install xxx -g 时, 模块将被下载安装到[全局目录]中. [全局目录]通过 npm config set prefix "目录路径" 来设置. 比如说, ...
- java基础之io流总结三:字节流读写
字节流读写适用于任何文件,包括图片,视频等. 基本字节流 一次读一个字节和一次读一个字节数组 FileInputStream fis = new FileInputStream(path); //一次 ...
- elasticsearch2.x插件之一:kopf
kopf kopf is a simple web administration tool for elasticsearch written in JavaScript + AngularJS + ...
- HTML5样式、链接和表格
-------------------siwuxie095 HTML5 样式 1.标签 <style> 标签:样式定义 <link> 标签:资源引用 2.属性 rel:用于指定 ...
- Java 基于quartz实现定时 之一(注解方式配置)
需要在项目里,导入quartz.jar package cn.zr.pringmvctest.trigger; import org.springframework.context.annotatio ...
- 面试题:try,catch,finally都有return语句时执行哪个 已看1
1.不管有木有出现异常,finally块中代码都会执行: return 先执行 把值临时存储起来, 执行完finally之后再取出来 值是不会改变的2.当try和catch中有return时,fina ...
- xgboost 完全调参指南
http://www.2cto.com/kf/201607/528771.html xgboost: https://www.analyticsvidhya.com/blog/2016/03/comp ...
- wireshark抓取qq数据包
抓包接口设置成本地连接 点击start,登录qq,输入oicq进行过滤qq包 找到第一个OICQ,点击后,点击oicq-IM software 可以看到自己登录的QQ号码为765343409 本机IP ...
- 编写高质量代码改善C#程序的157个建议——建议39:了解委托的实质
建议39:了解委托的实质 理解C#中的委托需要把握两个要点: 1)委托是方法指针. 2)委托是一个类,当对其进行实例化的时候,要将引用方法作为它的构造方法的参数. 设想这样一个场景:在点对点文件传输过 ...