codeforces 858b
来源:互联网 发布:淘宝网刷销量 编辑:程序博客网 时间:2024/05/23 19:18
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
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 of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
10 36 22 17 3
4
8 43 16 25 22 1
-1
暴力
#include<iostream>#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;struct node{int num;int fl;}x[110];int main(){int n,m;scanf("%d%d",&n,&m);int k,f;int a=-1;for(int i=0;i<m;i++)scanf("%d%d",&x[i].num,&x[i].fl);int ans=-1;for(int i=1;i<=110;i++){int j;for(j=0;j<m;j++){int temp=x[j].num/i;if(x[j].num%i)temp++;if(temp!=x[j].fl)break;}if(j==m){int res=n/i+(n%i>0?1:0);if(ans!=-1&&ans!=res){printf("-1\n");return 0;}ans=res;}}printf("%d\n",ans);}
- codeforces 858b
- CodeForces 858B Which floor?
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- codeforces B. Coins
- codeforces----193B Xor
- codeforces----208B Solitaire
- Codeforces 1B - Spreadsheet
- codeforces 214B Hometask
- Codeforces Round #136 B
- python 学习笔记
- Matlab格式化文本写操作
- &&和||短路运算
- VS2012打开项目后显示不可用,项目文件被卸载
- LeetCode Rotate Image
- codeforces 858b
- 代理模式
- noip2008 传纸条 T3题解
- Java利用POI导出Excel设置单元格格式
- 筛选合理的关键词以及网站雏形布局
- 2012ICPC长春站 K Yet Another Multiple Problem 【BFS+同余模定理】
- 利用springmvc提供一个HandlerExceptionResolver接口实现出错返回Json数据
- 移动架构09_Activity的启动流程分析
- Qt中QComboBox下拉列表(popup)位置与样式的控制