19056 简单数学
时间限制:1000MS 代码长度限制:10KB
提交次数:0 通过次数:0
题型: 编程题 语言: 不限定
Description
在一个平面直角坐标系中,给出n个一元一次方程组,y=kx+b,k,b为非负整数,小明希望算出至少p条直线的y值>=m时, 最小的正整数x为多少?
输入格式
输入为多case 第一行为一个T 表示数据组数,每组数据第一行包括三个整数n,p,m,表示方程的个数,最少要有多少条直线,y值需要大于等于多少。 接着是n行,每行有一个k和b 1<=p<=n<=10^5 0<=k<=10^3 0<=b<=10^9 1<=m<=10^9
输出格式
每组数据输出一行,表示最小的正整数x,数据保证有答案。
输入样例
1 2 1 5 2 2 2 3
输出样例
1
#include <iostream>
#include <cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cstring>
#include<map>
typedef long long ll;
using namespace std;
vector<double>ans;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
ll t;
cin>>t;
while(t--){
ans.clear();
ll n,p,m;
cin>>n>>p>>m;
for(int i=0;i<n;i++){
double k,b;
cin>>k>>b;
if(k==0){
if(b>=m)p--;
//当斜率为0 的时候,b>m才可以有一条直线符合条件
//否则无效
}else{
//k!=0时
double res = (m-b)/(double)k;
ans.push_back(res);
}
}
if(ans.size())sort(ans.begin(),ans.end());
if(p<=0)cout<<1<<endl;
else{
double res = ans[p-1];
if(res<=1)cout<<1<<endl;
else {
int tres;
if(res == (int)res)tres = (int)res;
else tres = (int)res+1;
cout<<tres<<endl;
}
}
}
return 0;
}