noip 2012 提高组 day2 部分题解

这道题有多种解法,我用的是扩展欧几里得算法求到的答案
#include<iostream>
#include<fstream>
#include<cstdio>
using namespace std;
typedef long long ll;
ifstream fin("mod.in");
FILE *fout = fopen("mod.out","w");
void gcd(ll a,ll b,ll& x,ll& y){
if(!b){ x = , y = ; }
else{ gcd(b, a%b, y, x); y -= x * (a / b); }
}
ll a1,b1;
ll x1 = ,y1 = ;
int main(){
fin>>a1>>b1;
gcd(a1, b1, x1, y1);
fprintf(fout,"%ld",(x1 + b1 * )%b1);
return ;
}


这道题把第i个人看做一个有序的序列(1、2、3、4....)然后二分
至于求和,就像这么处理:
、
接着从前面开始求和。。。

就像这样可以求出每一天的教室使用量,如果1 ~ v天中有哪一天不够用了,就在前半段
查找,如果都足够,就向后面查找,每次不够的时候更新结果result
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cctype>
#include<cstring>
using namespace std;
typedef bool boolean;
FILE *fout = fopen("classroom.out","w");
template <class T>
inline void get(T &u){
char x;
while(!isdigit(x=getchar()));
for( u=x-; isdigit(x=getchar()); u*=,u+=(x-));
ungetc(x,stdin);
}
int *d;
int *s;
int *t;
int *r;
int *buf;
int m,n;
boolean solve(int v){
memset(buf, , sizeof(int) * (n + ));
int sum = ;
int limit = ;
for(int i = ;i <= v;i++){
buf[s[i]] += d[i];
buf[t[i] + ] -= d[i];
limit = max(limit, t[i]);
}
for(int i = ;i <= limit;i++){
sum += buf[i];
if(sum > r[i]) return true;
}
return false;
}
int main(){
freopen("classroom.in","r",stdin);
get(n);
get(m);
r = new int[(const int)(n + )];
d = new int[(const int)(m + )];
s = new int[(const int)(m + )];
t = new int[(const int)(m + )];
buf = new int[(const int)(n + )];
for(int i = ;i <= n;i++) get(r[i]);
for(int i = ;i <= m;i++){
get(d[i]);
get(s[i]);
get(t[i]);
}
int from = ;
int end = m;
int result = ;
while(from <= end){
int mid = (from + end) >> ;
if(solve(mid)){
result = mid;
end = mid - ;
}else from = mid + ;
}
if(!result) fprintf(fout,"0\n");
else fprintf(fout,"-1\n%d\n",result);
return ;
}
noip 2012 提高组 day2 部分题解的更多相关文章
- noip 2013 提高组 Day2 部分题解
积木大赛: 之前没有仔细地想,然后就直接暴力一点(骗点分),去扫每一高度,连到一起的个数,于是2组超时 先把暴力程序贴上来(可以当对拍机) #include<iostream> #incl ...
- NOIP 2015 提高组 Day2
期望得分:100+10+60=170 实际得分:100+10+35=145 http://www.cogs.pro/cogs/page/page.php?aid=16 T1 跳石头 时间限制:1 s ...
- NOIP 2013 提高组 day2 积木大赛
积木大赛 描述 春春幼儿园举办了一年一度的“积木大赛”.今年比赛的内容是搭建一座宽度为 n 的大厦,大厦可以看成由 n 块宽度为1的积木组成,第
- Vigenère 密码NOIP 2012 提高组 第一天 第一题
题目描述 16 世纪法国外交家 Blaise de Vigenère 设计了一种多表密码加密算法――Vigenère 密 码.Vigenère 密码的加密解密算法简单易用,且破译难度比较高,曾在美国南 ...
- NOIP 2014 提高组 Day2
期望得分:100+60+30=190 实际得分:70+60+30=160 https://www.luogu.org/problem/lists?name=&orderitem=pid& ...
- NOIP 2008提高组第三题题解by rLq
啊啊啊啊啊啊今天已经星期三了吗 那么,来一波题解吧 本题地址http://www.luogu.org/problem/show?pid=1006 传纸条 题目描述 小渊和小轩是好朋友也是同班同学,他们 ...
- NOIP 2014 提高组 题解
NOIP 2014 提高组 题解 No 1. 生活大爆炸版石头剪刀布 http://www.luogu.org/problem/show?pid=1328 这是道大水题,我都在想怎么会有人错了,没算法 ...
- NOIP 2001 提高组 题解
NOIP 2001 提高组 题解 No 1. 一元三次方程求解 https://vijos.org/p/1116 看见有人认真推导了求解公式,然后猥琐暴力过的同学们在一边偷笑~~~ 数据小 暴力枚举即 ...
- noip 2014 提高组初赛
noip 2014 提高组初赛 一. TCP协议属于哪一层协议( ) A. 应用层 B. 传输层 C. 网络层 D. 数据链路层 B TCP(传输控制协议) 若有变量int a; float: x, ...
随机推荐
- HDFS Snapshots
Overview HDFS Snapshots are read-only point-in-time copies of the file system. Snapshots can be take ...
- vue.js个人学习心得
2017.4.7开始辞职刚好一个月时间,一个月时间里我开始彷徨,迷惘,失业带来的痛苦,打算转行,不再搞机械行业,因为不想再做低端的产品设计(本身不是研究生也不是说天资卓越,只是不甘于平凡). 好了,不 ...
- 【make install】自定义安装目录,添加动态链接库 【--prefix】 【ldconfig】 【LD_LIBRARY_PATH】
怎么卸载make install安装的软件? https://www.zhihu.com/question/20092756 怎么指定安装目录以及对应的添加动态库的方法 linux库在不指定安装路径时 ...
- Memcached与redis的比较--stackoverflow(转)
原文:http://blog.nosqlfan.com/html/3729.html 这两年Redis火得可以,Redis也常常被当作Memcached的挑战者被提到桌面上来.关于Redis与Memc ...
- xpath教程 2 - lxml库
xpath教程 2 - lxml库 这些就是XPath的语法内容,在运用到Python抓取时要先转换为xml. lxml库 lxml 是 一个HTML/XML的解析器,主要的功能是如何解析和提取 HT ...
- vertx 从Tcp服务端和客户端开始翻译
写TCP 服务器和客户端 vert.x能够使你很容易写出非阻塞的TCP客户端和服务器 创建一个TCP服务 最简单的创建TCP服务的方法是使用默认的配置:如下 NetServer server = ve ...
- Scala里面如何使用枚举
枚举通常用来定义已知数量的常量,比如月份,星期,季节等等,用过java的人都知道定义枚举的关键字是enum,在scala里面和java有所不同,来看一个完整的例子定义: object EnumTest ...
- 实习培训——Java基础(1)
实习培训——Java基础(1) 1.我的第一个JAVA程序 首先好配置好JDK环境,百度上有很多.创建文件HelloWorld.java(文件名与类名相同),代码如下: public class He ...
- 基于androidstudio3.0的build文件配置问题
最近,在研究APP自动化相关的东西,在搭建环境的时候,遇到的坑以及最后解决的方法,不过目前很多东西了解得还不是很细,暂时先简单的记录一下一.build配置文件 主要分为两种: 1.工程下的build配 ...
- Air Jordan 1 Los Primeros Will be unveiled
This new pair of Air Jordan 1 Los Primeros is part of the popular Air-Jordan- Line signature and is ...