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

200題記念

Posted by tozangezan at 2010-06-01 15:28:26 on Problem 2209
#include<stdio.h>
#include<math.h>
#include<algorithm>
int main(){
	int a;
	int b;
	int c[100];
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%d",c+i);
	}
	std::sort(c,c+a);
	int ans=0;
	if(b%2){
		for(int i=a-1;i>=0;i--){
			if(c[i]<0)break;
			else ans+=(int)pow((double)c[i],(double)b);
		}
	}else{
		for(int i=0;i<a;i++)ans+=(int)pow((double)c[i],(double)b);
	}
	printf("%d\n",ans);
}

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