CodeForces 232E.Quick Tortoise】的更多相关文章

John Doe has a field, which is a rectangular table of size n × m. We assume that the field rows are numbered from 1 to n from top to bottom, and the field columns are numbered from 1 to m from left to right. Then the cell of the field at the intersec…
题意: 思路: //By SiriusRen #include <cstdio> #include <bitset> #include <vector> using namespace std; int n,m,q; char map[505][505],ans[600005]; struct Node{int x1,y1,x2,y2,id;}jy; vector<Node>vec; bitset<505>a[505][505],b[505][5…
\(\mathcal{Description}\)   Link.   在一张 \(n\times m\) 的网格图中有空格 . 和障碍格 #,\(q\) 次询问,每次查询从 \((x_1,y_1)\) 出发,是否能仅向下或向右走,在不经过障碍格的情况下走到 \((x_2,y_2)\).   \(n,m\le500\),\(q\le6\times10^5\). \(\mathcal{Solution}\)   Trick 向的分治解法.   不妨按行分治,设当前分治区间为 \([l,r]\),取…
这一题由于数据较多,我们考虑离线处理. 分治.对于两个点s,t,如果起点在mid这条横线上方,终点在下方,那么它必定会穿过mid这条线.所以只要s可以到mid上一点x,x可以到t,st就是安全的. 用bitset维护.设\(f1[i][j]\)为上方ij到mid这条线的是否可以的01值,\(f2[i][j]\)为下方ij到mid的01值.将f1[sx][sy]&f2[tx][ty],如果结果存在1,那么就能走到. Codeforces版本 #include <cstdio> #incl…
题意 题目链接 Sol 感觉这个思路还是不错的 #include<bits/stdc++.h> using namespace std; const int MAXN = 501, SS = 5e6 + 10; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '…
题目大意: 给你一个$n\times m(n,m\leq 500)$的格子,有一些是障碍物.从一个格子出发只能向下或向右走,有$q$组询问,每次询问从一个点是否能够到达另一个点. 思路: 分治. 两点间的路径必然会经过两点间的某条竖线. 我们可以二分一个区间内中间一条线$mid$, 对于$mid$左边的点,求出到$mid$为止往右下走能够到达的点, 对于$mid$右边的点,求出从$mid$开始往右下走会被哪些点到达. 这可以用bitdet来存. 对于不经过这条竖线的路径,可以往下递归查找. 回答…
题目链接:http://codeforces.com/contest/327/problem/C 首先先算出一个周期里面的值,保存在ans里面,就是平常的快速幂模m做法. 然后要计算一个公式,比如有k个部分,那么对于没一个位置i, 都有2^i + 2^(i+n) + ... + 2^(i+(k-1)*n) = 2^i(1 + 2^n + ... + 2^((k-1)*n)) = 2^i * (1-2^(n*k))/(1-2^n) 所以结果就是ans * (1-2^(n*k))/(1-2^n) %…
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“-1”. 数据范围: 1 ≤ n ≤ 100, 2 ≤ t ≤ 10 so easy!首先考虑无解的时候,只有当n==1,t==10是无解,其他情况都存在解.很容易想到最简单的n位数能被t整除的数是,t个n组成的数. 参考代码: By Royecode, contest: Codeforces Ro…
http://codeforces.com/contest/938 A:sb题 //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragm…
http://codeforces.com/contest/678 A:水题 #include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define C 0.5772156649 #define ls l,m,rt<…