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

贴个0ms的代码

Posted by KatrineYang at 2016-05-26 18:20:35 on Problem 1607
//============================================================================
// Name        : main1607.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <iomanip>
#include <cmath>
#include <stdio.h>
using namespace std;

int main() {
	cout << "Cards  Overhang" << endl;
	int num;
	double ress[100000] = {0};
	int max = 0;
	while(cin >> num){
		double res = 0;

		if(num > max){
			for(int i = max+1; i <= num; i++){
				ress[i] = ress[i-1] + 1.0/2/i;
			}

			max = num;

		}
		res = ress[num];
		int log = (int)log10(num * 1.0);
		for(int i = 0; i < 4 - log; i++){
			cout << " ";
		}
		cout << num;
		int spaces;
		if(res < 10) spaces = 5;
		else{
			spaces = 5 - (int)log10(res);
		}
		for(int i = 0; i < spaces; i++){
			cout << " ";
		}
		//cout << setprecision(3) << res << endl;
		printf("%.3lf\n", res);
	}
	//cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
	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