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 ...
随机推荐
- poj1273--Drainage Ditches(最大流Edmond-Karp算法 邻接表实现)
最大流模板题 大部分Edmond-Karp算法代码都是邻接矩阵实现,试着改成了邻接表. #include <iostream> #include <cstdio> #inclu ...
- IE-一根网线二台电脑上网
1 直连线 使用交叉线(橙白 橙 (蓝白) (绿 绿白) ( 蓝)宗白 棕) 2 如果主机原本是用ADSL拔号上网的话,就在主机的网络连接下的宽带连接右击属性>高级,在“Internet 连接共 ...
- mongodb的固定集合(优化效率)
mongodb固定集合(Capped Collection)和大文件管理(GridFS) Capped Collection 固定集合(Capped Collection)是性能出色的有着固定 ...
- hdoj 1406 完数
完数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- Oracle Tnsping慢
http://www.linuxidc.com/Linux/2014-02/96167.htm http://www.askmaclean.com/archives/dns%E8%AE%BE%E7%B ...
- OutLook中发送用户密码加密的小技巧
1 在左上栏目里面选择 New E-mail选项卡,点击进入发送新邮件页面. 2 在第一栏选择Options选项,点击打开 3 看到有一个红色按钮Perssion按钮,打开 4 ...
- SGU107——987654321 problem
For given number N you must output amount of N-digit numbers, such, that last digits of their square ...
- linux命令之cat
转自:http://www.cnblogs.com/peida/archive/2012/10/30/2746968.html cat命令的用途是连接文件或标准输入并打印.这个命令常用来显示文件内容, ...
- 每天进步一点达——MySQL——myisampack
一. 简单介绍 myisampack是一个压缩使用MyISAM引擎表的工具,通常会压缩40%~70%,当须要訪问数据.server会将所须要的信息读入到内存中.所以当訪问详细记录时,性能 ...
- Linq-表达式常用写法
这里主要是将数据库中的常用操作用LAMBDA表达式重新表示了下,用法不多,但相对较常用,等有时间了还会扩展,并将查询语句及LINQ到时也一并重新整理下:1.select语句:books.Select( ...