| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
水题就是用来秀的吼吼闲着没事把乘方从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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator