Codeforces858B which floor?
来源:互联网 发布:c语言函数声明与调用 编辑:程序博客网 时间:2024/06/09 20:12
标签:模拟
In a building where Polycarp lives thereare equal number of flats on each floor. Unfortunately, Polycarpdon't remember how many flats are on each floor, but he remembers that theflats are numbered from 1 from lower toupper floors. That is, the first several flats are on the first floor, the nextseveral flats are on the second and so on. Polycarp don't remember the totalnumber of flats in the building, so you can consider the building to beinfinitely high (i.e. there are infinitely many floors). Note that the floorsare numbered from 1.
Polycarp remembers on which floors several flats arelocated. It is guaranteed that this information is not self-contradictory. Itmeans that there exists a building with equal number of flats on each floor sothat the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore theexact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for,and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each ofthese lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which meansthat the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is notself-contradictory.
Output
Print the number of the floor in which the n-th flat islocated, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
input
10 3
6 2
2 1
7 3
output
4
input
8 4
3 1
6 2
5 2
2 1
output
-1
Note
In the first example the 6-th flat is on the 2-nd floor,while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floorand there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on eachfloor, so we can't restore the floor for the 8-th flat.
题意:一栋楼内有无穷多个房间,给出一部分房间位于第几层的数据,询问第q号房间位于第几层,如果存在唯一答案,则输出,否则输出-1,保证题目给出数据不自相矛盾
模拟水题,但是很容易WA,这个div2的B题通过率竟然比C题还低
Code
#include<bits/stdc++.h>#define rep(i,a,b) for(int i=a;i<=b;i++)#define dep(i,a,b) for(int i=a;i>=b;i--)#define LL long longusing namespace std;const int maxn=5000000;struct node{int num,fl;}x[maxn];inline int cmp(node a,node b){if(a.num==b.num)return a.fl<b.fl;else return a.num<b.num;}LL q,m,flag,temp,ans,t;int main(){cin>>q>>m;rep(i,1,m){cin>>x[i].num>>x[i].fl;}sort(x+1,x+1+m,cmp);rep(i,1,10000){flag=1; rep(j,1,m){ temp=x[j].num/i; if(x[j].num%i!=0)temp++;if(temp!=x[j].fl)flag=0;}if(flag==1){t=q/i;if(q%i!=0)t++;}if(ans==0)ans=t;if(ans!=t){cout<<"-1\n";return 0;}}rep(i,1,m-1){if(x[i].num<=q&&x[i+1].num>=q&&x[i].fl==x[i+1].fl){cout<<x[i].fl<<endl;return 0;}} cout<<ans<<endl; return 0;}
- Codeforces858B which floor?
- B. Which floor?
- Codeforces Round #434 Which floor?
- CodeForces 858B Which floor?
- floor
- Codeforces Round #434(div2)B-模拟&思维&读题-Which floor?
- which
- which
- which
- floor () 函数
- Math.floor
- Math.floor
- floor函数
- Math.floor
- Math.floor
- floor 函数
- floor函数
- Floor problem
- 【国际】俄罗斯部长:加密货币“不可忽视”
- Enqueue(队列等待)
- 【观点】英国央行官员:央行数字货币需要“非凡的”弹性
- python的内置函数
- 【资讯】盲目从众?美国银行调查显示比特币为“最拥挤交易”
- Codeforces858B which floor?
- [笔记]LCA 最近公共祖先---tarjan离线算法
- HTTP请求和响应
- Linux 根据进程名(或pid)查看其占用的端口
- BZOJ3252 攻略 [树链剖分][不用线段树]
- 【国际】博伊西市与区块链创业公司签订开发协议
- 【动态】Zcash开发人员发布新技术,改善zk-SNARK
- OpenWrt下通过EC20 R2.0 4G模块实现qmi拨号上网
- 【国际】迪拜金融监管机构发布ICO警告