codeforces 536a//Tavas and Karafs// Codeforces Round #299(Div. 1)
题意:一个等差数列,首项为a,公差为b,无限长。操作cz是区间里选择最多m个不同的非0元素减1,最多操作t次,现给出区间左端ll,在t次操作能使区间全为0的情况下,问右端最大为多少。
这么一个简单题吞了我3小时的时间。主要是没考虑全。
首先,得出ll位置的值a1,如果a1>t那么不可行。
然后分2种情况。
1.区间长度<=m,那么只要右端<=t就行,否则不行。
2.区间长度>m,区间内元素总和<=m*t,且右端<=t就行,否则不行。这个我猜到了,不过忽略了右端<=t,因此wa了很久。
乱码:
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon; int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon a,b,n;
cin>>a>>b>>n;
for(lon i=;i<n;++i)
{
lon ll,t,m;
cin>>ll>>t>>m;
lon lo=ll,hi=1e6+;
for(;lo<hi;)
{
lon mid=(lo+hi)/;
lon cur=;
lon a1=a+(ll-)*b;
lon len=(mid-ll+);
cur=a1*len+len*(len-)*b/;
bool ok=;
if(len<=m)
{
ok=(a+(mid-)*b)<=t;
}
else
{
ok=cur<=m*t&&(a+(mid-)*b)<=t;
}
//cout<<"cur: "<<cur<<endl;
//cout<<(m*t)<<" "<<ok<<" "<<lo<<" "<<hi<<" "<<"mid: "<<mid<<" "<<cur<<endl;
if(!ok)hi=mid;
else lo=mid+;
}
cout<<(lo-<ll?-:lo-)<<endl;
}
return ;
}
codeforces 536a//Tavas and Karafs// 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. 1) A. Tavas and Karafs 水题
Tavas and Karafs Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/536/prob ...
- Codeforces 535C - Tavas and Karafs
535C - Tavas and Karafs 思路:对于满足条件的r,max(hl ,hl+1 ,hl+2 ,......,hr )<=t(也就是hr<=t)且∑hi<=t*m.所 ...
- Codeforces Round #299 (Div. 2)A B C 水 dfs 二分
A. Tavas and Nafas time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 【Codeforces Round #299 (Div. 2) C】 Tavas and Karafs
[链接] 我是链接,点我呀:) [题意] 给你一个规则,让你知道第i根萝卜的高度为si = A+(i-1)*B 现在给你n个询问; 每次询问给你一个固定的起点l; 让你找一个最大的右端点r; 使得l. ...
- 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. 2) B. Tavas and SaDDas 水题
B. Tavas and SaDDas Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/535/p ...
随机推荐
- ActiveMQ 集群负载平衡
目前的架构: 负载均衡方案:========================================= 第二种方案呢,假设我们整个应用是个食堂,这个食堂里面有好多饭口,每个饭口有好多大爷大妈( ...
- linux常用命令:sudo 命令
sudo命令用来以其他身份来执行命令,预设的身份为root. 1.命令格式: sudo [参数] [命令] 2.命令功能: 功能: sudo可以针对单个命令授予临时权限.用户也可以通过su切换到 ...
- python3.4学习笔记(八) Python第三方库安装与使用,包管理工具解惑
python3.4学习笔记(八) Python第三方库安装与使用,包管理工具解惑 许多人在安装Python第三方库的时候, 经常会为一个问题困扰:到底应该下载什么格式的文件?当我们点开下载页时, 一般 ...
- C/C++之extern "C"的用法解析
extern "C"的用法解析 http://blog.sina.com.cn/u/494a1ebc010004g5 C++中extern “C”含义深层探索 1.引言 C++语言 ...
- python学习读取配置文件
配置文件作为一种可读性很好的格式,非常适用于存储程序中的配置数据. 在每个配置文件中,配置数据会被分组(比如“config”和 “cmd”). 每个分组在其中指定对应的各个变量值.如下: # 定义co ...
- 2018年星际争霸AI挑战赛–三星与FB获冠亚军,中科院自动化所夺得季军
雷锋网 AI 科技评论消息,2018 年 11 月 13-17 日,AAAI 人工智能与交互式数字娱乐大会 (AI for Interactive Digital Entertainment) 在阿尔 ...
- Linux启动vi编辑器时提示E325: ATTENTION解决方案
Linux启动vi编辑器时提示E325: ATTENTION解决方案 Vi编辑器是Linux的文本编辑器,在Linux系统的运用非常广泛,不少朋友在打开Vi编辑器的时候提示E325: ATTENTIO ...
- jQuery 对象
jQuery 对象 版权声明:未经博主授权,严禁转载分享 什么是 jQuery 对象 jQuery 对象是通过 jQuery 包装 DOM 对象后产生的对象. jQuery 对象是一个类数组对象. j ...
- 初步实现GoQtTemplate
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> //新添加 #include <opencv2/co ...
- 20145333茹翔 Exp5 利用nmap扫描
20145333茹翔 Exp5 利用nmap扫描 实验过程 首先使用命令创建一个msf所需的数据库 service postgresql start msfdb start 使用命令msfconsol ...