Codeforces Round #434 B

Which floor?

题意:一栋楼里每层有若干个公寓,每层的公寓数量相同,现在给出m个公寓的编号和所在楼层,问能否唯一确定第n公寓在第几层(公寓的编号1-100 从第一层开始有序)

思路:暴力每一层的公寓数(如果数据大可以二分),然后判断每一个已知编号楼层是否符合,要判断是否有多个不同的答案,可能存在多个答案但多个答案是一样的

AC代码:

#include "iostream"
#include "iomanip"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#pragma comment(linker, "/STACK:102400000,102400000")
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a,x) memset(a,x,sizeof(a))
#define step(x) fixed<< setprecision(x)<<
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ll long long
#define endl ("\n")
#define ft first
#define sd second
#define lrt (rt<<1)
#define rrt (rt<<1|1)
using namespace std;
const ll mod=1e9+7;
const ll INF = 1e18+1LL;
const int inf = 1e9+1e8;
const double PI=acos(-1.0);
const int N=1e5+100;

int f[1005];
struct Node{
    int a,b;
}x[1005];
int main(){
    int n,m,ans=0,anss=0;
    cin>>n>>m;
    for(int i=1; i<=m; ++i){
        cin>>x[i].a>>x[i].b;
        if(x[i].a==n){
            cout<<x[i].b<<endl;
            return 0;
        }
    }
    for(int i=1; i<=100; ++i){
        int now=1, k=1;
        for(int j=1; j<=100; ++j){
            if(k>i){
                now++, k=1;
            }
            f[j]=now, k++;
        }
        int flag=0;
        for(int j=1; j<=m; ++j){
            if(f[x[j].a]!=x[j].b){
                flag=1;
                break;
            }
        }
        if(flag==0 && anss!=f[n]){
            ans++;
            anss=f[n];
        }
    }
    if(ans==1) cout<<anss<<endl;
    else cout<<"-1\n";
    return 0;
}

 

posted on 2017-09-19 16:06  lazzzy  阅读(117)  评论(0编辑  收藏  举报

导航