Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:加减乘除都不用就把这题AC了!

Posted by nan5515522 at 2014-06-26 18:59:36 on Problem 1000
In Reply To:加减乘除都不用就把这题AC了! Posted by:nan5515522 at 2014-05-26 21:06:14
这题忒难了,总算想到二分法水过了!贴代码纪念一下!

#include <iostream>
#include <algorithm>
#include <cstdio>
#include<queue>
#include<vector>
using namespace std;

int bin(int a, int b)
{
	int start = 0, end = 100, middle;
	if(start - a -b == 0)
		return start;
	
	while(1)
	{
		middle = (start + end) / 2;
		if(middle - a - b == 0)
			return middle;
		else if(middle - a - b > 0)
			end = middle;
		else
			start = middle;
	}
	return -1;
}


int main()
{
	int a, b;
	cin >> a >> b;
	cout << bin(a, b) << endl;
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator