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

水题就是用来秀的吼吼

Posted by nan5515522 at 2014-05-25 17:49:23 on Problem 2209
闲着没事把乘方从O(n)给优化到O(log n)了,作水题也要自娱自乐一下的嘛!
#include<iostream> 
#include<Cstdio>
using namespace std; 

int sonSize, mi, sum, input;

int ans(int di, int ci)
{
	
	if(ci == 1)
		return di;
	if(ci == 0)
		return 1;
	int temp, result;
	if(ci % 2 == 0)
	{
		temp = ans(di, ci>>1);
		result = temp * temp;
	}
	else
	{
		temp = ans(di, ci>>1);
		result = temp * temp * di;
	}
	return result;
}
int main()  
{ 
	int i, temp;
	sum = 0;
	scanf("%d%d", &sonSize, &mi);
	for(i = 0; i < sonSize; i++)
	{
		scanf("%d", &input);
		temp = ans(input, mi);
		if(temp >= 0)
			sum += temp;
	}
	cout << sum << endl;
} 

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