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 ...
随机推荐
- c语言之sizeof总结
一.sizeof的概念 Sizeof是C语言的一种单目操作符,如C语言的其他操作符++.--等.它并不是函数.Sizeof操作符以字节形式给出了其操作数的存储大小.操作数可以是一个表达式或括在括号内的 ...
- POJ-3017 Cut the Sequence DP+单调队列+堆
题目链接:http://poj.org/problem?id=3017 这题的DP方程是容易想到的,f[i]=Min{ f[j]+Max(num[j+1],num[j+2],......,num[i] ...
- PHP面向对象编程
IBM 教程:开始了解 PHP 中的对象 简明现代魔法 一篇很好的入门的Class 文章 - 技术分享 - php教程 少走弯路去学习面向对象编程 -- 简明现代魔法
- PC问题-使用BAT方法设置IP地址
::------以下为批处理文件内容---- @echo off ::set slection1= set/p slection1=请输入IP地址: netsh interface ip set ad ...
- 性能优化-列表类型转换(ConvertList<TSource, TResult>)
之前,在项目中看到过一段通用列表类型转换的代码,直接的实现便是用反射.大概看了下,它用在领域模型转DTO和SOA接口中契约实体的转换等等.首先,它使用了反射,其次,还是在循环中使用,便有了优化的想法. ...
- 【Hibernate】--一对一关联、联合主键
一.数据模型 1.学生信息模型(编号.名称.身份信息) public class Student implements java.io.Serializable{ private static fin ...
- 跑马灯效果的TextView之singLine 和maxLines
Android 的TextView 里面有两个属性 singLine 和maxLines . 从字面意思来理解,这两个都是限制Text的行数.那么singleLine="true" ...
- Unity3D 导入贴图、模型等资源文件时自动设置参数
脚本继承至AssetPostprocessor, 存放在Editor目录下! using UnityEngine; using System.Collections; using UnityEdito ...
- Android代码中动态设置图片的大小(自动缩放),位置
项目中需要用到在代码中动态调整图片的位置和设置图片大小,能自动缩放图片,用ImageView控件,具体做法如下: 1.布局文件 <RelativeLayout xmlns:android=&qu ...
- EventBus3.0使用总结
在Android中,接口回调已经能够处理掉大部分业务需求了,实在太变态的需求就用广播也能够完成,自己写的性能好出问题也好解决.....工作需要,不得不看看EventBus的用法,今天就来介绍一下学习经 ...