链接
http://codeforces.com/problemset/problem/750/A
题意
小明12点要去一个聚会,但是他现在家并且,有n个题需要做,从他家到聚会地点需要k分钟,所以他需要先做题,然后再去聚会,他最多能够做几个题,对于第x个题,它需要5*x分钟;
题解
本题即是求满足(5+5*x)*x/2+k<=240的最大的x,枚举或二分,这里给出而二分的写法,需要注意的是二分的写法;
代码
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define inf 0x7f7f7f7f
#define maxn 100005
#define mod 1000000007
#define N 1
#define P 2
typedef long long ll;
int n, k;
int find(int val) {
int l=-1,r=n+1;
while(l<r-1){
int mid=(l+r)>>1;
if((5+5*mid)*mid/2>val)
r=mid;
else l=mid;
}
return l;
}
int main() {
cin >> n >> k;
cout << find(240 - k) << endl;
}