【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个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- POJ 1006 Biorhythms (数论-中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 111285 Accepted: 34638 Des ...
- oracle 数据库批处理文件
文件夹结构 初始化脚本 |----orcl_sql |----init_user.sql |----tab_home.sql |----TAB_USER.sql |----init.bat init. ...
- jQuery07源码 (3803 , 4299) attr() prop() val() addClass()等 : 对元素属性的操作
var nodeHook, boolHook, rclass = /[\t\r\n\f]/g, rreturn = /\r/g, rfocusable = /^(?:input|select|text ...
- 在电子商务里,一般会提到这样几个词:商品、单品、SPU、SKU
简单理解一下,SPU是标准化产品单元,区分品种:SKU是库存量单位,区分单品:商品特指与商家有关的商品,可对应多个SKU. 首先,搞清楚商品与单品的区别.例如,iphone是一个单品,但是在淘宝上当很 ...
- 2017国家集训队作业[arc082d]Sandglass
2017国家集训队作业[arc082d]Sandglass 题意: 有一个沙漏,初始时\(A\)瓶在上方,两个瓶子的最大容量都为\(X\)克,沙子流动的速度为\(1g\)每单位时间.给出\(K\) ...
- 压状态bfs
一般地图很小,状态不多,可以装压或者hash,构造压缩或hash的函数,构造还原地图的函数,然后就无脑bfs(感觉就是SPFA) 题目: 1.玩具游戏:二进制压缩状态 #include<cstd ...
- hostname---显示和设置系统的主机
hostname命令用于显示和设置系统的主机名称.环境变量HOSTNAME也保存了当前的主机名.在使用hostname命令设置主机名后,系统并不会永久保存新的主机名,重新启动机器之后还是原来的主机名. ...
- 从excel 获取内容 模块:xlrd
import xlrd # 获取表的对象 excel = xlrd.open_workbook(‘a.excel’) # 获取所有excel里的所有表 table_list = excel.sheet ...
- windows查看硬件信息系统信息
rem 查看cpu wmic cpu list briefrem 查看物理内存wmic memphysical list briefrem 查看逻辑内存wmic memlogical list bri ...
- 【Hello 2018 A】 Modular Exponentiation
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 当a<b的时候 a%b==a 显然2^n增长很快的. 当2^n>=1e8的时候,直接输出m就可以了 [代码] #incl ...