NOIP2011 题解
铺地毯
题解:比大小
#include <cstdio>
const int MAXN = +;
int n, x, y, a[MAXN], b[MAXN], g[MAXN], k[MAXN];
inline int Solve(){
for (int i=n; i>; i--)
if (a[i]<=x && x<=a[i]+g[i] && b[i]<=y && y<=b[i]+k[i]) return i;
return -;
}
int main(){
scanf("%d", &n);
for (int i=; i<=n; i++)
scanf("%d %d %d %d", &a[i], &b[i], &g[i], &k[i]);
scanf("%d %d", &x, &y);
printf("%d\n", Solve());
}
carpet.cpp
选择客栈:
题解:模拟。cj表示最近的一个可行的咖啡馆,tot[i]表示之前颜色i出现过的次数legal[i]表示颜色i在cj之前出现过的次数,last[i]表示颜色i最后出现的编号
#include <cstdio>
#include <cstring> const int MAXK = +; int n, k, p, color, cost, cj, Pri, legal[MAXK], tot[MAXK], last[MAXK];
char c; inline int NextInt(){
int ret = ;
do
c = getchar();
while (!(<=c && c<=)); do
ret *= , ret += c-, c = getchar();
while (<=c && c<=); return ret;
} int main(){
memset(tot, , sizeof(tot));
memset(legal, , sizeof(legal)); n = NextInt(), k = NextInt(), p = NextInt(), Pri = ;
for (int i=; i<=n; i++){
color = NextInt(), cost = NextInt();
if (cost<=p) cj = i;
if (cj>=last[color]) legal[color] = tot[color];
Pri += legal[color] , tot[color] ++, last[color] = i;
}
printf("%d\n", Pri);
}
hotel.cpp
计算系数:
题解:组合数+快速幂。之前一直wa,直到把一些变量变成long long,然后多mod几次,就过了...
聪明的质检员:
题解:二分
#include <cstdio>
#include <algorithm>
#define LL "%lld"
using namespace std; typedef long long ll;
const int MAXN = +;
const ll INF = 1e12; ll n, m, s, L, R, Mid, Pri, w[MAXN], l[MAXN], r[MAXN], v[MAXN], sum[MAXN], sumv[MAXN]; inline bool check(int x){
for (int i=; i<=n; i++)
if (w[i]>=x)
sum[i] = sum[i-]+,
sumv[i] = sumv[i-]+v[i];
else
sum[i] = sum[i-],
sumv[i] = sumv[i-]; ll cj = ;
for (int i=; i<=m; i++)
cj += (sum[r[i]]-sum[l[i]-])*(sumv[r[i]]-sumv[l[i]-]); Pri = min(Pri, abs(cj-s));
return s<=cj;
} int main(){
scanf(LL LL LL, &n, &m, &s), L = Pri = INF, R = -INF;
for (int i=; i<=n; i++)
scanf(LL LL, w+i, v+i),
L = min(L, w[i]), R = max(R, w[i]);
for (int i=; i<=m; i++)
scanf(LL LL, l+i, r+i); while (L<=R){
Mid = (L+R)>>;
if (check(Mid)) L = Mid+;
else R = Mid-;
}
printf(LL, Pri);
}
check.cpp
NOIP2011 题解的更多相关文章
- NOIP2011题解
NOIP2011其实早就做完了....一直懒得写.... Day1 T1铺地毯 我什么都不想说,不会做您就没必要接着看了.... #include<iostream> using name ...
- Noip2011瑞士轮题解
题目背景 在双人对决的竞技性比赛.如乒乓球.羽毛球.国际象棋中.最常见的赛制是淘汰赛和循环赛.前者的特点是比赛场数少.每场都紧张刺激,但偶然性较高.后者的特点是较为公平,偶然性较低,但比赛过程往往十分 ...
- 题解【洛谷P1315】[NOIP2011]观光公交
题目描述 风景迷人的小城 Y 市,拥有 \(n\) 个美丽的景点.由于慕名而来的游客越来越多,Y 市特意安排了一辆观光公交车,为游客提供更便捷的交通服务. 观光公交车在第 \(0\) 分钟出现在 \( ...
- NOIP2011聪明的质监员题解
631. [NOIP2011] 聪明的质监员 ★★ 输入文件:qc.in 输出文件:qc.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 小 T 是一名质量监督 ...
- 题解 【NOIP2011】计算系数
[NOIP2011]计算系数 Description 给定一个多项式 (ax+by)^k ,请求出多项式展开后 x^n * y^m 项的系数. Input 共一行,包含 5 个整数,分别为 a,b,k ...
- 题解【洛谷P1314】[NOIP2011]聪明的质监员
题面 题解 不难发现,\(W\)增大时,\(Y\)值会随之减小. 于是考虑二分\(W\). 如何\(\mathcal{O}(N)check?\) 每一次前缀和记录一下\(1-i\)之间\(w_i \g ...
- [NOIP2011]观光公交 题解
题目大意: 就省了吧 思路: 应该算是贪心. 不难发现,加速只对所有在使用加速器之后连续的一段下车时不用等人的站点下车的人有用.这非常重要. 先算出不加速时的和,并预处理出每个站点最迟到的人的时间.每 ...
- [NOIP2011]聪明的质监员 题解
题目大意: 额--貌似蛮清晰的,就不赘述了. 思路: 首先不难发现M越大Y越小,因此可以二分答案(方向不要弄错),二分出最小的不小于S的Y即可.而计算Y时可用前缀和O(n+m)求得.两种边界情况也要考 ...
- [NOIP2011]Mayan游戏 题解
题目大意: 有一个5*7的方格,上面有几种颜色的方块,如果在一横行或者竖列上有连续三个或者三个以上相同颜色的方块,则它们将立即被消除,方块消除之后,消除位置之上的方块将掉落.每步移动可以且仅可以沿横向 ...
随机推荐
- HashTable,HashSet与Dictionary
1.HashTable 哈希表(HashTable)表示键/值对的集合.在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现 ...
- How to force the UI to refresh immediately(WPF)
Question 0 Sign in to vote Folks, In my application, when the user hits "Submit" button, I ...
- NSIS打包(一)常用概念简介
1.NSIS简介 官网:http://sourceforge.net/projects/nsis/ 维基百科: http://zh.wikipedia.org/wiki/Nullsoft%E8%85% ...
- 使用Atlas实现MySQL读写分离
1.MySQL所在机器 192.168.29.128(Master) 192.168.29.129(Slave) 配置好主从同步,参考 http://www.cnblogs.com/luxh/p/40 ...
- 21. Clone Graph
Clone Graph Clone an undirected graph. Each node in the graph contains a label and a list of its nei ...
- LR11-更改licence
准备工作: 超级licence 6.5w:AEACFSJI-YJKJKJJKEJIJD-BCLBR AEACFSJI-YJKJKJJKEJIJD-BCLBR 操作步骤: 1.网上下载lr删除注册表工具 ...
- mysql Can't connet MySQL server to '@localhost'
10063/10060/10038好像都能解决 mysql -nt -remove mysql -nt install
- VS2010 "error MSB8011” 解决方法
http://blog.csdn.net/heihei36/article/details/8923971 —————————————————————————————————————————————— ...
- 第九十九天上课 PHP TP框架 数据库查询和增加
在Model文件夹下创建模型,文件命名规则 : 表名Model.class.php <?php namespace Home\Model; use Think\Model; class yong ...
- objective c, protocol
OC中协议类似于java中的接口,在多个类具有类似的方法时可以将这些方法定义到protocol中,然后各个类分别实现protocol中的各个方法. 例:有两个类Square和Circle, 定义一个p ...