CF861B

http://www.elijahqi.win/archives/881
B. Which floor?
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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?

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 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.

Output
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.

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 floor and 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 each floor, so we can’t restore the floor for the 8-th flat.

一共n只有100所以暴力枚举

枚举每层有多少个房间,然后验证是否正确,如果满足所有给的条件,就算一个n对应的层数

然后看n会对应几个层数,超过1就是-1

#include<cstdio>
#include<set>
#define N 110
int n,m,num[110],fl[110]; 
int main(){
    freopen("cf.in","r",stdin);
    scanf("%d%d",&n,&m);
    if (n==1) {printf("1");return 0;}
    if (m==0){printf("-1");return 0;}
    for (int i=1;i<=m;++i) scanf("%d%d",&num[i],&fl[i]);
    int ans=0,cnt=0,tmp;
    for (int i=1;i<=100;++i){
        bool flag=true;
        for (int j=1;j<=m;++j)
            if (num[j]<=(fl[j]-1)*i||num[j]>fl[j]*i){flag=false;break;}
        if (flag) {
            ++cnt;
            if (n%i==0) {
                ans=n/i;if (cnt==1) tmp=ans;if (ans!=tmp) {printf("-1");return 0;}
            }else {
                ans=n/i+1;if (cnt==1) tmp=ans;if (ans!=tmp) {printf("-1");return 0;}
            }
        }
    }
    printf("%d",tmp);
    return 0;
}
01-01 00:13:46.024 2141 2141 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 01-01 00:13:46.024 2141 2141 F DEBUG : Build fingerprint: 'realme/RMP2502IN/RE6453L1:15/UKQ1.231108.001/V.R4T1.50f6fcd-329ace1:user/release-keys' 01-01 00:13:46.024 2141 2141 F DEBUG : Revision: '0' 01-01 00:13:46.024 2141 2141 F DEBUG : ABI: 'arm64' 01-01 00:13:46.024 2141 2141 F DEBUG : Timestamp: 2025-01-01 00:13:45.939000309-0500 01-01 00:13:46.024 2141 2141 F DEBUG : Process uptime: 1s 01-01 00:13:46.025 2141 2141 F DEBUG : Cmdline: /odm/bin/hw/subsys_daemon -l /odm/lib64/lib-virtual-modem-radio-aidl.so -i 0 01-01 00:13:46.025 2141 2141 F DEBUG : pid: 2129, tid: 2129, name: Binder:subsys_d >>> /odm/bin/hw/subsys_daemon <<< 01-01 00:13:46.025 2141 2141 F DEBUG : uid: 1001 01-01 00:13:46.025 2141 2141 F DEBUG : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE) 01-01 00:13:46.025 2141 2141 F DEBUG : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr -------- 01-01 00:13:46.025 2141 2141 F DEBUG : Abort message: 'Pointer tag for 0x7e1a931148 was truncated, see 'https://source.android.com/devices/tech/debug/tagged-pointers'.' 01-01 00:13:46.025 2141 2141 F DEBUG : x0 0000000000000000 x1 0000000000000851 x2 0000000000000006 x3 0000007ffcfe9560 01-01 00:13:46.025 2141 2141 F DEBUG : x4 7260761f37333030 x5 7260761f37333030 x6 7260761f37333030 x7 7f7f7f7f7f7f7f7f 01-01 00:13:46.025 2141 2141 F DEBUG : x8 00000000000000f0 x9 0000007e9f6f1608 x10 0000000000000001 x11 0000007e9f77aa50 01-01 00:13:46.025 2141 2141 F DEBUG : x12 000000006774cf09 x13 000000007fffffff x14 00000000000046b2 x15 000000002887433f 01-01 00:13:46.025 2141 2141 F DEBUG : x16 0000007e9f7e6f00 x17 0000007e9f7cf990 x18 0000007ea0ad0000 x19 0000000000000851 01-01 00:13:46.025 2141 2141 F DEBUG : x20 0000000000000851 x21 00000000ffffffff x22 0000007ffcfe96f1 x23 b400007e9ab482d0 01-01 00:13:46.025 2141 2141 F DEBUG : x24 0000007ea0354000 x25 000000000000002f x26 0000000000000000 x27 0000000000000000 01-01 00:13:46.025 2141 2141 F DEBUG : x28 0000000000000000 x29 0000007ffcfe95e0 01-01 00:13:46.025 2141 2141 F DEBUG : lr 0000007e9f762d58 sp 0000007ffcfe9540 pc 0000007e9f762d88 pst 0000000000001000 01-01 00:13:46.025 2141 2141 F DEBUG : 12 total frames 01-01 00:13:46.025 2141 2141 F DEBUG : backtrace: 01-01 00:13:46.025 2141 2141 F DEBUG : #00 pc 0000000000097d88 /apex/com.android.runtime/lib64/bionic/libc.so (abort+168) (BuildId: c23c39d0e7aacb7c4fb733dcd0e3cb19) 01-01 00:13:46.025 2141 2141 F DEBUG : #01 pc 00000000000515a8 /apex/com.android.runtime/lib64/bionic/libc.so (free+120) (BuildId: c23c39d0e7aacb7c4fb733dcd0e3cb19) 01-01 00:13:46.025 2141 2141 F DEBUG : #02 pc 0000000000023318 /odm/lib64/android.hardware.radio.voice-V1-ndk.so (ndk::ICInterface::ICInterfaceData::onDestroy(void*)+56) (BuildId: 34939db762097ad95945235c0867116b) 01-01 00:13:46.025 2141 2141 F DEBUG : #03 pc 0000000000014b28 /system/lib64/libbinder_ndk.so (ABBinder::~ABBinder()+72) (BuildId: 032745f0978de18ef9c83c1aa861b553) 01-01 00:13:46.026 2141 2141 F DEBUG : #04 pc 0000000000010c40 /system/lib64/libutils.so (android::RefBase::decStrong(void const*) const+160) (BuildId: e335e75b9933dbd38e10c5e8d7994c7e) 01-01 00:13:46.026 2141 2141 F DEBUG : #05 pc 0000000000048588 /odm/lib64/lib-virtual-modem-radio-aidl.so (RadioVoiceImpl::init(int, PlatformType)+472) (BuildId: c07f7ab3a500dda751ae00a36df388cf) 01-01 00:13:46.026 2141 2141 F DEBUG : #06 pc 000000000002b510 /odm/lib64/lib-virtual-modem-radio-aidl.so (PadRadioService::init()+176) (BuildId: c07f7ab3a500dda751ae00a36df388cf) 01-01 00:13:46.026 2141 2141 F DEBUG : #07 pc 000000000002b844 /odm/lib64/lib-virtual-modem-radio-aidl.so (onLoad+244) (BuildId: c07f7ab3a500dda751ae00a36df388cf) 01-01 00:13:46.026 2141 2141 F DEBUG : #08 pc 000000000000a3c4 /odm/bin/hw/subsys_daemon (DaemonApp::onCreate(int, char**)+820) (BuildId: cb91cf2af2c33f45fe0290d22e5b85e4) 01-01 00:13:46.026 2141 2141 F DEBUG : #09 pc 000000000000222c /odm/lib64/libmindroid-app.so (MainThread::main(int, char**)+156) (BuildId: 5971af6c09bfbd6373fefc3044d07b6f) 01-01 00:13:46.026 2141 2141 F DEBUG : #10 pc 0000000000002178 /odm/lib64/libmindroid-app.so (main+8) (BuildId: 5971af6c09bfbd6373fefc3044d07b6f) 01-01 00:13:46.026 2141 2141 F DEBUG : #11 pc 0000000000091524 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+116) (BuildId: c23c39d0e7aacb7c4fb733dcd0e3cb19) 01-01 00:13:46.099 2147 2147 F DEBUG : Process name is /odm/bin/hw/subsys_daemon -l /odm/lib64/lib-virtual-modem-radio-aidl.so -i 1, uid is 1001, not key_process 01-01 00:13:46.100 2147 2147 F DEBUG : keyProcess: 0
最新发布
06-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值