CodeForces 796A Buying A House

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces 796A Buying A House相关的知识,希望对你有一定的参考价值。


题目链接:​​http://codeforces.com/contest/796/problem/A​​​
题意:给你n个房子,a[i]表示房子的价格,m表示你住的地方,k表示你有多少钱,a[i]等于零好像是指有人住,然后让你找一个买得起又尽可能离m近的地方住,让你输出最小距离是多少,每隔一个房子距离加10(反正我是看着样例和hint猜的题意O__O “…)
解析:把所以小于等于k的位置都存起来,然后看一下谁最小,然后结果肯定是min(ans,abs(i-m)*10)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
using namespace std;
const int maxn = 1e5+100;
const int inf = 0x7ffffff;
const int mod = 1e9;
int a[105];
vector<int>ans;
int main(void)

int n,m,k;
scanf("%d %d %d",&n,&m,&k);
for(int i=1;i<=n;i++)

scanf("%d",&a[i]);
if(a[i]<=k && a[i]!=0)
ans.push_back(abs(i-m));

sort(ans.begin(),ans.end());
printf("%d\\n",ans[0]*10);
return 0;


以上是关于CodeForces 796A Buying A House的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #546 (Div. 2)-D - Nastya Is Buying Lunch

codeforces103E Buying Sets

codeforces 103E Buying Sets

CodeForces - 799B-T-shirt buying (优先队列)

A. Buying Torches1000 / 贪心

Codeforces-Round#546(Div.2)-D-Nastya Is Buying Lunch