二分法的细节注意

在利用二分法时,有的人常常会写成

int mid = ( left + right) / 2;

但是这个是不严谨的,在left+right > INT_MAX时会出现错误。
因此推荐使用

int mid = left + ( right - left) / 2;

示例如下:

#include<iostream>
using namespace std;
int main()
{
    int a = 1, b = INT_MAX;
    int mid1 = (a + b) / 2;
    int mid2 = a + (b - a) / 2;
    cout << "mid1 = "<< mid1 << endl;
    cout << "mid2 = "<< mid2 << endl;
    return 0;
}

结果
这里写图片描述

Beginning JavaScript with DOM Scripting and Ajax, 2nd Edition (pdf + ePub) by Russ Ferguson and Christian Heilmann Publisher: Apress; 2nd Edition (July 2013) Language: English ISBN-10: 1430250925 ISBN-13: 978-1430250920 BOOK DESCRIPTION Beginning JavaScript with DOM Scripting and Ajax is an essential resource for modern JavaScript programming. This completely updated second edition covers everything you need to know to get up-to-speed with JavaScript development and add dynamic enhancements to web pages, right from the basics. As well as focusing on client-side JavaScript, you will also learn how to work with the Browser Object Model, the Document Object Model (DOM), how to use XML and JSON as well as communicate with service side scripts such as PHP. Find out how to: Construct good JavaScript syntax following modern coding practices Use JavaScript to communicate with the server and retrieve data Dynamically manipulate markup, validate forms and deal with images Debug applications using features inside the browser JavaScript is one of the most important technologies on the web. It provides the means to add dynamic functionality to your web pages and serves as the backbone of Ajax-style web development. Beginning JavaScript with DOM Scripting and Ajax will take you from being a JavaScript novice to work freely with this important technology – begin your JavaScript journey today! What you'll learn What functions, variables, events and objects are and how to use them. How build a site that will still work in the case that JavaScript is turned off. How to access and update part of the page using code. How to use JavaScript to communicate with the server and retrieve data. How to use JavaScript to for form validation and user feedback. How to use Third-Party Libraries like jQuery. Who this book is for Beginning JavaScript with DOM Scripting and Ajax is for the person who has a good grasp of HTML and CSS but wants to add JavaScript to their skillset. If you want to learn some basic programming concepts, have experience but need help updating your skills, or you’re coming from another language, Beginning JavaScript with DOM Scripting and Ajax can help. Table of Contents Chapter 1. Getting Started with JavaScript Chapter 2. Data and Decisions Chapter 3. From DHTML to DOM Scripting Chapter 4. HTML and JavaScript Chapter 5. Presentation and Behavior (CSS and Event Handling) Chapter 6. Common Uses of JavaScript: Images and Windows Chapter 7. JavaScript and User Interaction: Navigation and Forms Chapter 8. Back-End Interaction with Ajax and Node.js Chapter 9. Data Validation Techniques Chapter 10. Modern JavaScript Case Study: A Dynamic Gallery Chapter 11. Using Third-Party JavaScript Appendix A. Debugging JavaScript
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值