Codeforces 861 B Which floor? 思维
题目链接: http://codeforces.com/contest/861/problem/B
题目描述: 每个楼梯上有相同数量的数, 都是从1开始, 给你m个不矛盾的信息, 问你能不能判断n在第几层
解题思路: 这道题我看到的时候觉得只要能算出来一层有多少个数就可以了, 就是暴力层数, 就可以了, 复杂度为O(n^2), 但是要注意的情况就是有的时候就算不知道确切的层数, 我也可以判断n在几层, 所以我的想法错了.....改进就是将所有可能的答案推进vector中, 最后看看可能答案是不是一个数就可以了
代码:
#include <iostream> #include <cstdio> #include <map> #include <iterator> #include <string> #include <algorithm> #include <vector> #include <cmath> using namespace std;typedef long long ll;const int maxn = 108; int a[maxn]; int b[maxn]; vector<int> ans; int main() {int n, m;cin >> n >> m;for( int i = 1; i <= m; i++ ) {cin >> a[i] >> b[i];}for( int e = 1; e <= 100; e++ ) {int flag = 1;for( int i = 1; i <= m; i++ ) {int floor = a[i]/e + (a[i]%e!=0);if( floor != b[i] ) {flag = 0;break;}}if( flag ) {ans.push_back(e);}}int flag = 1;vector<int>::iterator it = ans.begin();int res = n/(*it) + (n%(*it)!=0);for( it = ans.begin(); it != ans.end(); it++ ) {if( (n/(*it) + (n%(*it)!=0)) != res ) {flag = 0;break;}}if( flag ) {cout << res << endl;}else {cout << -1 << endl;}return 0; }
View Code
思考: 在转化等价条件的时候必须严格证明其正确性
转载于:https://www.cnblogs.com/FriskyPuppy/p/7614705.html
Codeforces 861 B Which floor? 思维相关推荐
- Codeforces 1077B Disturbed People(思维题)
Codeforces 1077B Disturbed People(思维题) There is a house with nn flats situated on the main street of ...
- CodeForces - 160D Edges in MST(思维+tarjan/树链剖分+线段树)
题目链接:点击查看 题目大意:给出一张 n 个点 m 条边组成的带权无向图,现在对于每条边来说,确定一下其分类: 一定是最小生成树上的边 可能是最小生成树上的边 一定不是最小生成树的边 题目分析:两种 ...
- Codeforces 861 A k-rounding 数论
题目链接: http://codeforces.com/contest/861/problem/A 题目描述: 给你一个n, 一个k, 让你求n的所有倍数至少以k个0结尾的那个数 解题思路: 质因数分 ...
- Codeforces 846 A Curriculum Vitae 思维 暴力
题目链接: http://codeforces.com/contest/846/problem/A 题目描述: 给你一个串, 你可以做删除操作, 要求结果串0不能在1的右边, 问最多可以剩几个数字 解 ...
- CodeForces - 1494E A-Z Graph(构造+思维)
题目链接:https://vjudge.net/problem/CodeForces-1494E 题目大意:给出一个初始时只有 nnn 个点的有向带权图,需要执行 mmm 次操作,每次操作分为下列三种 ...
- CodeForces - 1504C Balance the Bits(思维+构造)
题目链接:https://vjudge.net/problem/CodeForces-1504C 题目大意:给出一个长度为 nnn 的 010101 串,现在要求构造出两个长度为 nnn 的合法括号序 ...
- CodeForces - 594A Warrior and Archer(思维+博弈)
题目链接:点击查看 题目大意:给出n个坐标轴上的点,两个人轮流操作,每次取走其中的一个点,直到最后剩余两个点为止,Vova先手,Vova希望两个点的距离尽可能小,Lesha希望两个点的距离尽可能大,问 ...
- CF--思维练习--CodeForces - 216C - Hiring Staff (思维+模拟)
ACM思维题训练集合 A new Berland businessman Vitaly is going to open a household appliances' store. All he's ...
- CF--思维练习--CodeForces - 219C Color Stripe (思维)
ACM思维题训练集合 A colored stripe is represented by a horizontal row of n square cells, each cell is paine ...
最新文章
- 019_MySQL正则表达式
- 云原生语境下,如何重新解读微服务?
- php 打印变量内存地址_Python合集之Python变量
- ubuntu c 判断程序是否启动_刚刚接触编程的我,怎么判断自己是否适合做一个程序员?...
- oracle 48小时内_缺血性脑梗死后48小时内使用阿替普酶能够降低脑损伤程度
- 【渝粤教育】国家开放大学2018年春季 8622-22T社会调查研究与方法 参考试题
- c语言判断回文平方数,C/C++回文数的判断(转)
- Ado.Net 实体类、数据连接类、数据访问类
- linux安装mysql要先装jdk吗_linux安装mysql5.7.22,tomcat,jdk
- 推荐Python互动艺术在线编辑器(腾讯扣叮)
- 文本文件的输入输出流(这里的重点在于字符集问题)
- 8.1.1使用BlockingQueue和ArrayBlockingQueue
- 顺序右移数组元素(内测第0届第5题)
- 二维图像(数组)的fftshift
- 高通mtk手机常用指令
- Native开发工具之静态库和动态库(二,小码农也有大梦想
- Forwarding Address字段
- iOS——编译与链接
- Android接入第三方QQ登录
- 中国大学Mooc浙大翁恺老师《零基础学Java语言》编程作业(续)(5~ 7)