【Codeforces Round #434 (Div. 2) B】Which floor?
【链接】h在这里写链接
【题意】
【题解】
【错的次数】
【反思】
【代码】
#include <bits/stdc++.h>
using namespace std; const int N = 200; int n, m, cur = 0, idx = 0;;
int should[N + 10]; void ok(int per) {
int now = 1, cnt = 0;//now 是当前的楼层,cnt是当前楼层的公寓数目
int temp = 1;
for (int dd = 1; dd <= 100; dd++) {//枚举第dd间房子在哪里
cnt++;//当前楼层的公寓数目递增。
if (cnt > per) {//如果公寓数目大于每层的楼层数
cnt = 1;//进入下一层
now++;//楼层个数递增
}
if (should[dd] != 0 && should[dd] != now) return;
if (dd == n) temp = now;
//如果dd公寓不应该在第now层.就结束
}
//是一个合法的分配
if (cur == 0) {//如果之前没有找到过合法的。
idx = temp;//第n个房子,它就在第now层
cur = 1;//找到的解数目为1
}
else {//数目大于0了
if (cur == 1) {//如果只有一个解的话
if (idx == temp) return;//如果第n间房子的层数和当前一样.退出
}
cur++;//否则,答案递增。
}
} int main() {
//freopen("F:\\rush.txt", "r", stdin);
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
should[x] = y;//x号公寓房子啊第y层
}
for (int i = 1; i <= 102; i++)//枚举每层有i间公寓
ok(i);
if (cur > 1 || cur == 0)//如果解的个数太多,或没解。
cout << -1 << endl;
else
cout << idx << endl;
return 0;
}
【Codeforces Round #434 (Div. 2) B】Which floor?的更多相关文章
- 【Codeforces Round #434 (Div. 1) B】Polycarp's phone book
[链接]h在这里写链接 [题意] 给你n个电话号码. 让你给每一个电话号码选定一个字符串s; 使得这个串s是这个电话号码的子串. 且不是任何一个其他电话号码的子串. s要求最短. [题解] 字典树. ...
- 【Codeforces Round #434 (Div. 2) A】k-rounding
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 转换一下就是求n和10^k的最小公倍数. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc++ ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
- 【Codeforces Round #423 (Div. 2) A】Restaurant Tables
[Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- cogs 32. [POI1999] 位图
32. [POI1999] 位图 ★ 输入文件:bit.in 输出文件:bit.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述 ] 给定一个 n*m 的矩形位图, ...
- 如何获取repeater某行第一列的值
<div> <asp:Repeater ID="Repeater1" runat="server" DataMember="Defa ...
- java中TCP传输协议
class TcpClient { public static void main(String[] args) throws Exception { //创建client的socket服务,指定目的 ...
- android framework 02
Android底层开发1.安装Ubuntu系统2.Ubuntu配置开发环境: sudo apt-get install git-core gnupg flex bison gperf zip sudo ...
- 63.note.js之 Mongodb在Nodejs上的配置及session会话机制的实现
转自:https://www.cnblogs.com/alvin_xp/p/4751784.html 1.第一步安装mongodb数据库,这直接官网下载,这里不介绍. 2.也可以使用npm实现直接下载 ...
- Kinect 开发 —— 进阶指引 (下)
运动识别 利用运动识别(motion detection)来进行近景识别是最有意思的一种方式.实现运动识别的基本原理是设置一个起始的基准RGB图像,然后将从摄像头获取的每一帧影像和这个基准图像进行比较 ...
- 【DRF认证】
目录 认证组件的详细用法 本文详细讲述了DRF认证组件的原理以及用法. @ * 源码剖析** 上一篇博客讲解DRF版本的时候我们都知道了,在dispatch方法里执行了initial方法来初始化我们的 ...
- Flask框架简介
Flask框架诞生于2010年,是Armin ronacher 用python语言基于Werkzeug工具箱编写的轻量级Web开发框架! Flask本身相当于一个内核,其他几乎所有的功能都要用到扩展. ...
- Python - 字典按值(value)排序
字典安值排序是一个伪命题. 字典本身是不能被排序的, 已经依照关键字(key)排序, 可是列表(list)和元组(tuple)能够排序, 所以字典须要转换列表后排序. 如 import operato ...
- [NowCoder]牛客OI周赛3
A.地斗主 题意:\(4\times N\) 的地板,在上面铺 \(1\times 2\) 和 \(2\times 1\) 的地砖,求铺满方案数, \(N\le 10^9\) 原题..先把一列的状态压 ...