CodeForces - 796A Buying A House
思路:从m直接向两边枚举,如果当前点需要的费用小于等于k,说明一定是最近距离。
AC代码
#include <cstdio> #include <cmath> #include <cctype> #include <algorithm> #include <cstring> #include <utility> #include <string> #include <iostream> #include <map> #include <set> #include <vector> #include <queue> #include <stack> using namespace std; #pragma comment(linker, "/STACK:1024000000,1024000000") #define eps 1e-10 #define inf 0x3f3f3f3f #define PI pair<int, int> typedef long long LL; const int maxn = 100 + 5; int a[maxn]; int main() { int n, m, k; while(scanf("%d%d%d", &n, &m, &k) == 3) { for(int i = 1; i <= n; ++i) { scanf("%d", &a[i]); } int ans; for(int i = 1; i < n; ++i) { if(m-i > 0 && a[m-i] <= k && a[m-i]) { ans = i; break; } if(m+i <= n && a[m+i] <= k && a[m+i]) { ans = i; break; } } printf("%d\n", ans*10); } return 0; }
如有不当之处欢迎指出!
CodeForces - 796A Buying A House的更多相关文章
- 【codeforces 796A】Buying A House
[题目链接]:http://codeforces.com/contest/796/problem/A [题意] 让你选一个最靠近女票的,且能买的房子; 输出你和你女票的距离; [题解] 枚举 [Num ...
- CodeForces - 799B-T-shirt buying (优先队列)
题目链接 /* Name: Copyright: Author: Date: 2018/5/2 16:09:54 Description:优先队列 */ #include <iostream&g ...
- codeforces 796A-D
决定在 codeforces 练题啦,决定每个比赛刷前四道...太难就算了 796A Buying A House 题意:给出x轴上的n 个点,每个点有个权值,问离m 点最近的权值小于等于k 的点离m ...
- Codeforces GYM 100876 J - Buying roads 题解
Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...
- Codeforces 1136D - Nastya Is Buying Lunch - [贪心+链表+map]
题目链接:https://codeforces.com/problemset/problem/1136/D 题意: 给出 $1 \sim n$ 的某个排列 $p$,再给出若干 $(x,y)$ 表示当序 ...
- 【codeforces 103E】 Buying Sets
http://codeforces.com/problemset/problem/103/E (题目链接) 题意 给出$n$个数,每个数与一个集合相关联.从其中选出最小的若干个数,选出的数的个数与这些 ...
- Codeforces 799B - T-shirt buying(STL)
题目链接:http://codeforces.com/problemset/problem/799/B 题目大意:有n件T恤,每件T体恤都分别有价格(每件衣服的价格不重复).前面的颜色.背部的颜色三种 ...
- Codeforces Round #413 B. T-shirt buying
B. T-shirt buying time limit per test 3 seconds memory limit per test 256 megabytes A new pack ...
- CodeForces - 799B T-shirt buying 【贪心】
题目链接 http://codeforces.com/problemset/problem/799/B 题意 给出N件衣服 pi 表示 第i件衣服的价格 ai 表示 第i件衣服的前面的颜色 bi 表示 ...
随机推荐
- Android之MaterialDesign应用技术2-仿支付宝上滑搜索框缓慢消失
PS:在这之前也就是上一篇介绍了MaterialDesign一些滑动删除.标题栏的悬浮效果等,如果没看过第一篇的小火鸡可以看一下,因为这篇是接着上一篇写的,有一些东西上一篇写过了这里就不在重复了(Ma ...
- freemarker中值比较的写法
因为freemarker中不能使用<.>的方式进行值的比较,大于使用gt,小于使用lt.所以集合大于0判断,如下: <#if students?size gt 0><#i ...
- Gsp
Gsp 接触到了groovy开发,自然就接触到了gsp.在grails开发中,gsp作为Grails的视图技术,事实上, 不过是标准 HTML 加上一些提供动态内容的 Grails 标记而已. gsp ...
- PHP date函数详解
在页面的最前页加上date_default_timezone_set(PRC); /*把时间调到北京时间,php5默认为格林威治标准时间*/date ()a: "am"或是 ...
- 【转】5 Best Place to Learn Linux – Linux Tutorial Sites
Linux have amazed every tech guy and make them curious to hands on Linux. Many of us not feel Linux ...
- java存放数据的5个地方
1.寄存器:最快的存储区,位于处理器内部,但是寄存器的数量极其有限,所以寄存器根据需求进行分配,你不 能直接控制,也不能在程序中感觉到寄存器存在的任何迹象.(C/C+允许向寄存器建议寄存器配, 但它不 ...
- PHPSTUDY下升级mysql后无法启动
说来也是搞笑,之前很早就想看Laravel了~其中,之前项目忙,还有就是自己也出了点事故!但是呢,我个人哭过,抱怨过,但是我还是很懂我自己的.也许没心没肺也是一种好事,但也是坏事~ 闲话说多了,来说正 ...
- jQuery中的DOM操作------复制及包裹节点
1.复制节点: 如果单击<li>元素后需要再复制一个<li>元素,可以用clone()方法来完成: $(this).clone().appendTo("ul" ...
- Cypher查询语言--Neo4j之聚合函数(五)
目录 聚合Aggregation 计数 计算节点数 分组计算关系类型 计算实体数 计算非空可以值数 求和sum 平均值avg 最大值max 最小值min 聚类COLLECT 相异DISTINCT 聚合 ...
- POJ 1704 Georgia and Bob [阶梯Nim]
题意: 每次可以向左移动一个棋子任意步,不能跨过棋子 很巧妙的转化,把棋子间的空隙看成石子堆 然后裸阶梯Nim #include <iostream> #include <cstdi ...