UVA 11261 - Bishops(杂题)
来源:互联网 发布:untitled软件汉化版 编辑:程序博客网 时间:2024/05/01 00:03
题目链接:点击打开链接
思路:
象可以沿着对角线走任意距离, 直接枚举保存复杂度n*m*log(nm), 肯定超时, 考虑到数学方法: 同主对角线上y-x的值相同, 同一副对角线上x+y相同, 且连续分布。
所以我们考虑枚举主对角线的值, 如果这个值出现过, 那么这一个对角线的所有点都会被攻击, 否则, 我们维护这个区间的副对角线被占有的值的个数。
复杂度O(nlogn)
细节参见代码:
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <string>#include <vector>#include <stack>#include <ctime>#include <bitset>#include <cstdlib>#include <cmath>#include <set>#include <list>#include <deque>#include <map>#include <queue>#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a)<(b)?(a):(b))using namespace std;typedef long long ll;typedef long double ld;const double eps = 1e-6;const double PI = acos(-1);const int mod = 1000000000 + 7;const int INF = 0x3f3f3f3f;// & 0x7FFFFFFFconst int seed = 131;const ll INF64 = ll(1e18);const int maxn = 4e4 + 10;int T,n,m,vis[maxn*2], sum1[maxn*2], sum2[maxn*2], kase = 0;struct node { int x, y; node(int x=0, int y=0):x(x), y(y) {} bool operator < (const node& rhs) const { if(x != rhs.x) return x < rhs.x; else return y < rhs.y; }}a[maxn];map<int, int> p;int main() { scanf("%d",&T); while(T--) { scanf("%d%d", &n, &m); p.clear(); memset(vis, 0, sizeof(vis)); for(int i = 1; i <= m; i++) { scanf("%d%d", &a[i].x, &a[i].y); a[i].x--; a[i].y--; int cur = a[i].x + a[i].y; vis[cur] = 1; cur = a[i].y - a[i].x; p[cur] = 1; } for(int i = 0; i <= 2*(n-1); i++) { if(i) { if(i&1) sum1[i] = sum1[i-1] + vis[i], sum2[i] = sum2[i-1]; else sum2[i] = sum2[i-1] + vis[i], sum1[i] = sum1[i-1]; } else { if(i&1) sum1[i] = vis[i], sum2[i] = 0; else sum2[i] = vis[i], sum1[i] = 0; } } int l = n-1, r = n-1, ans = 0; for(int i = -(n-1); i <= (n-1); i++) { if(p.count(i)) { ans += (r - l)/2+1; } else { if(r & 1) ans += sum1[r] - sum1[l-1]; else ans += sum2[r] - sum2[l-1]; } if(i < 0) l--, r++; else l++, r--; } printf("Case #%d: %d\n", ++kase, n*n-ans); } return 0;}
0 0
- UVA 11261 - Bishops(杂题)
- uva 11261 Bishops
- Little Bishops(UVa 861)
- uva 10237 bishops
- Uva-861-Little Bishops
- uva 861 Little Bishops
- uva 10237 - Bishops(dp)
- UVA - 10237 Bishops
- UVA 10237 Bishops
- UVa Problem 861 Little Bishops (棋盘上的象)
- UVa 10237 Bishops (组合数学)
- UVA 10237 - Bishops(递推)
- UVA10237:Bishops(dp)
- sgu220Little Bishops(dp)
- UVa Problem Solution: 861 - Little Bishops
- UVa 861 Little Bishops (组合数学)
- uva 10237 Bishops 黑白染色处理
- uva 861 Little Bishops 组合数学 (布棋)
- ios FMDB第三方库操作SQLite数据库
- Git 学习(篇六 --储藏与清理)
- PHP对象类型在内存中的分配
- web.xml中context-param如何引用依赖jar包中的配置文件
- Flask实践Step by Step -- 模板
- UVA 11261 - Bishops(杂题)
- Javascript—substring/slice/substr
- 2017国家公务员考试招27601人职位表下载-国家公务员考试网
- c++实践--cocos2dx, 2048v1.0
- java se 中的数组理解
- sort_buffer_size:
- 日常训练20161013 棋盘上的象
- react-native 启动服务器时候报错Could not install the app on the device, read the error above for details.
- bootstrap基础知识