Codeforces Round #299 (Div. 1)
Problem A:
实际上对于一段数字假设和为k,每次取较大的m个进行t次减一操作,最多减去的是min(m*t,k).
明白了这个结论就可以直接二分答案了。
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL A, B, n;
LL l, t, m, ans;
int main() {
ios::sync_with_stdio ();
cin >> A >> B >> n;
for (int i = ; i <= n; i++) {
cin >> l >> t >> m;
LL a = A + (l - ) * B;
int el = l, er = l + t, last = -;
while (el <= er) {
int mid = (el + er) >> ;
LL b = A + (mid - ) * B;
if ( (a + b) * (mid - l + ) / <= t * m && b <= t && t >= a) last = mid, el = mid + ;
else
er = mid - ;
}
cout << last << endl;
}
}
536A
Problem B:
对于匹配串p,的位置xi和xj 只要判断是否有冲突,没有的冲突的话,统计确定的位置的数量k,答案就是26^(n-k).否则答案就是0.
判断冲突利用KMP的next数组就行了.
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = ;
const int MOD = int (1e9 + );
int n, m;
int p[MAXN];
char s[MAXN];
int main() {
ios::sync_with_stdio ();
cin >> n >> m >> (s + );
int len = strlen (s + );
for (int i = , j = ; i <= len; i++) {
if (j && s[j + ] != s[i]) j = p[j];
if (s[j + ] == s[i]) j++;
p[i] = j;
}
int k = ;
for (int i = , x, y = ; i <= m; i++) {
cin >> x;
if (y && y + len > x) {
int tem = len;
while (p[tem] > y + len - x)
tem = p[tem];
if (p[tem] != y + len - x) {
cout << << endl;
return ;
}
else k -= y - x;
}
else if (y && y + len <= x) k += len;
y = x;
}
if(m) k += len;
LL ans = , tem = ;
k = n - k;
while (k) {
if (k & ) ans = (ans * tem) % MOD;
tem = (tem * tem) % MOD;
k >>= ;
}
cout << ans << endl;
}
536B
Codeforces Round #299 (Div. 1)的更多相关文章
- 二分搜索 Codeforces Round #299 (Div. 2) C. Tavas and Karafs
题目传送门 /* 题意:给定一个数列,求最大的r使得[l,r]的数字能在t次全变为0,每一次可以在m的长度内减1 二分搜索:搜索r,求出sum <= t * m的最大的r 详细解释:http:/ ...
- 水题 Codeforces Round #299 (Div. 2) A. Tavas and Nafas
题目传送门 /* 很简单的水题,晚上累了,刷刷水题开心一下:) */ #include <bits/stdc++.h> using namespace std; ][] = {" ...
- DFS Codeforces Round #299 (Div. 2) B. Tavas and SaDDas
题目传送门 /* DFS:按照长度来DFS,最后排序 */ #include <cstdio> #include <algorithm> #include <cstrin ...
- Codeforces Round #299 (Div. 2) D. Tavas and Malekas kmp
题目链接: http://codeforces.com/problemset/problem/535/D D. Tavas and Malekas time limit per test2 secon ...
- Codeforces Round #299 (Div. 1) A. Tavas and Karafs 水题
Tavas and Karafs Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/536/prob ...
- Codeforces Round #299 (Div. 2) B. Tavas and SaDDas 水题
B. Tavas and SaDDas Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/535/p ...
- Codeforces Round #299 (Div. 2) A. Tavas and Nafas 水题
A. Tavas and Nafas Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/535/pr ...
- Codeforces Round #299 (Div. 2)【A,B,C】
codeforces 535A-水题: #include <bits/stdc++.h> using namespace std; typedef long long LL; char s ...
- Codeforces Round #299 (Div. 1)C. Tavas and Pashmaks (凸壳)
C. Tavas and Pashmaks Tavas is a cheerleader in the new sports competition named "Pashmaks&qu ...
随机推荐
- HIVE中查询FAILED: Error in metadata: javax.jdo.JDOFatalDataStoreException: Communications link failure
有一天早上到公司用hive中查询数据,发现报错不能连接.通过检查发现mysql服务器没有启动,开启mysql服务器后查询正常.
- nyoj 915 +-字符串
+-字符串 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 Shiva得到了两个只有加号和减号的字符串,字串长度相同.Shiva一次可以把一个加号和它相邻的减号交换. ...
- fcntl记录锁实例
fcntl 函数是一个相当常用的对文件进行加锁操作的函数. 文件锁包括强制锁.建议锁.记录锁, 不过一般系统和内核都是用的强制锁. 以下为记录锁的例子:------------------------ ...
- Java用OpenOffice将word转换为PDF
一. 软件安装以及jar包下载 官网的下载地址如下(英文): OpenOffice 下载地址http://www.openoffice.org/ JodConverter 下载地址http: ...
- 从零开始,打造自己的首个 iOS 框架
如果你曾试图创建自己的iOS框架,你知道这不是一个头脑发热作出的决定 — 管理依赖以及写测试用例一点也不简单.本教程将会带你从头到尾创建你的第一个iOS框架,让你可以创建自己的框架. 我们将在框架暴露 ...
- Iperf使用方法
Iperf使用方法 Iperf 是一个网络性能测试工具.Iperf可以测试TCP和UDP带宽质量.Iperf可以测量最大TCP带宽,具有多种参数和UDP特性.Iperf可以报告带宽,延迟抖动和数据包 ...
- 测试浏览器最多能包含Cookie的个数和Cookie中包含的最多内容
public class CookieTestServlet extends HttpServlet { public void doGet(HttpServletRequest request, H ...
- gulp 实践
文档站YDoc 相关注意事项 sass 编译 目录结构 可以直接使用sass编译 ➜ ydoc git:(v2) ✗ sass ./sass/app.scss ./template/source/ap ...
- error: Error: No resource found that matches the given name (at 'layout_above' with value '@id/btnLayout').
今天在练习fragment碎片的时候,进行界面布局的时候出现了这个问题. 后来解决后发现原因很简单:就是因为在布局xml文件中,引用ID和声明ID的顺序必须保证声明在前,引用在后.和布局的顺序无关. ...
- sklearn两种保存模型的方式
作者:卢嘉颖 链接:https://www.zhihu.com/question/27187105/answer/97334347 来源:知乎 著作权归作者所有,转载请联系作者获得授权. 1. pic ...