• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

读完题马上就想到了二分答案,但是就是写了半天才写出来。

在二分的时候精度的缺失是问题所在。

#includeiostream

使用命名空间标准

int k;

双Cal(双A) {

双n=A-3500,ans=0;

如果(A=3500)返回a;

如果(编号80000) {

ans=(n-80000)* 0.45;

n=80000

}

如果(编号55000) {

ans=(n-55000)* 0.35;

n=55000

}

如果(编号35000) {

ans=(n-35000)* 0.30;

n=35000

}

如果(编号9000) {

ans=(n-9000)* 0.25;

n=9000

}

如果(编号4500) {

ans=(n-4500)* 0.20;

n=4500

}

如果(n 1500) {

ans=(n-1500)* 0.10;

n=1500

}

if(n 0) {

ans=n * 0.03

}

返回a-ans;

}

布尔校验(双中间){

if(Cal(mid)=k) {

返回真实的

}否则返回错误的

}

int Find(int n) {

双EPS=1e-5;//精度

双l=1,r=100000000

while(epsr-l) {

double mid=(l r)/2;

if(check(mid))l=mid;

else r=mid

}

返回l 0.05

}

int main() {

CIN k;

//cout Cal(k);

if(k=3500)cout k;

否则{

cout Find(k);

}

}

这个两倍型的二分模板需要特殊记一下:

int Find(int n) {

双EPS=1e-5;//精度

双l=1,r=100000000

while(epsr-l) {

double mid=(l r)/2;

if(check(mid))l=mid;

else r=mid

}

返回l 0.05

}

还有如何四舍五入:

返回l 0.05

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now