Codeforces Round #434(div2)B-模拟&思维&读题-Which floor?
2017-09-22 10:58
357 查看
http://codeforces.com/contest/861/problem/B
第一次竟然没看懂啥意思。。
有一栋公寓,每一栋有相同的房间数,给你n个房间所在的楼层。
问能否确定第m号房间在哪个楼层。
数据范围100。直接暴力枚举房间数就行。
但是有一点要注意,就是当不同房间数导致 m所在楼层不同时,才记录。。用一个 map存一下。
还有,就是用ceil的时候,里面要求为浮点数qwq
第一次竟然没看懂啥意思。。
有一栋公寓,每一栋有相同的房间数,给你n个房间所在的楼层。
问能否确定第m号房间在哪个楼层。
数据范围100。直接暴力枚举房间数就行。
但是有一点要注意,就是当不同房间数导致 m所在楼层不同时,才记录。。用一个 map存一下。
还有,就是用ceil的时候,里面要求为浮点数qwq
#include <bits/stdc++.h> using namespace std; /* 数据范围最多100,就是100层。 我们就枚举 每层的数量, 来看看这些条件是否都符合。 */ vector<pair<int,int> >v; bool judge(int s){ bool flag=true; int l,r; for(int i=0;i<v.size()&&flag;i++){ l=(v[i].second-1)*s+1; r=l+s-1; if(v[i].first>=l&&v[i].first<=r) ; else flag=false; } return flag; } bool mp[105]; int main() { int m,n,a,b; int sum,s; while(~scanf("%d%d",&m,&n)){ v.clear(); memset(mp,0,sizeof(mp)); for(int i=0;i<n;i++){ scanf("%d%d",&a,&b); v.push_back(make_pair(a,b)); } sum=0; s=0; for(int i=1;i<=102;i++){ if(judge(i)){ if(!mp[(int)ceil((1.0*m)/(1.0*i))]){ mp[(int)ceil((1.0*m)/(1.0*i))]=true; sum++; s=i; //cout<<(int)ceil(m/i)<<endl; //cout<<s<<endl; } //cout<<i<<endl; } } if(sum>=2) puts("-1"); else{ printf("%d\n",(int)ceil((1.0*m)/(s*1.0))); } } return 0; }
相关文章推荐
- hdu6205-模拟&思维-card card card
- 51nod1785-好题&思维&模拟窗口-数据流算法
- Codeforces Round #364(Div. 2) A. Cards【模拟】 && B. Cells Not Under Attack【SET/规律】
- Codeforces Round #360 (Div. 2) 前三题题解【简单模拟+思维+二分图判定二分染色】
- Codeforces Round #419 (Div. 2)-贪心&思维-C. Karen and Game
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B(模拟) && codeforce 724B Batch Sort
- Uva 10881 Piotr's Ants (模拟+思维)
- Codeforces Round #210 (Div. 2) C. Levko and Array Recovery && Codeforces 360 A 详解(思维+维护理论值)
- Codeforces Round #354 (Div. 2) B. Pyramid of Glasses (模拟+思维)
- Codeforces Round #378 (Div. 2) && codeforces 733D(思维枚举)
- HDU5961-搜索|模拟&思维&好题-A - 传递
- Codeforces Round #366 (Div. 2) A 【水题】& B【博弈】 & C 【思维】
- POJ1068 Parencodings(模拟&思维)
- Codeforces Round #386 (Div. 2)C. Tram(模拟+思维)
- Codeforces Round #350 (Div. 2) E 思维模拟
- Codeforces Round #408 (Div. 2) 思维,模拟,DP, 多点BFS
- Codeforces Round #423 (Div. 2) C. String Reconstruction(思维 模拟)
- Codeforces Round #363(Div. 2) A. Launch of Collider【模拟】 && B. One Bomb【暴力】
- hpuoj 【1141】蜗牛爬树【模拟】&&【思维】
- Codeforces Round #195 (Div. 2) / 336A Vasily the Bear and Triangle(模拟&数学)