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:贡献了无数次WA,最后一组测试数据到底是什么?

Posted by yuajuan at 2016-08-24 11:18:10 on Problem 2566
In Reply To:贡献了无数次WA,最后一组测试数据到底是什么? Posted by:animate at 2005-08-16 16:58:36
> #include<cstdio>
> #include<iostream>
> #include<cmath>
> #include<utility>
> using namespace std;
> int n,k;
> pair<int,int> table[100010];
> 
> void Solve(int t){
> 	int i=0,j=1;
> 	int delta=-1,temp;
> 	int value,indexi,indexj;
> 
>          //为什么我把下面的注释掉就是AC,不注释就是WA?-____-||
>          /*
>          delta=abs(table[1].first-table[0].first-t);
>          value=table[1].first-table[0].first;
>          indexi=0;indexj=1;	
>          */
> 
> 	while(j<n&&delta){
> 		int cur=table[j].first-table[i].first;
> 		temp=abs(t-cur);
> 		if(delat==-1||temp<delta){
> 			delta=temp;
> 			value=cur;
> 			indexi=table[i].second;
> 			indexj=table[j].second;
> 		}
> 		if(cur<t)j++;
> 		if(cur>t)i++;
> 		if(i==j)j++;
> 	}
> 	
> 	if(indexi<indexj)
> 		printf("%d %d %d\n",value,indexi+1,indexj);
> 	else
> 		printf("%d %d %d\n",value,indexj+1,indexi);
> }
> 
> int main(){
> 	while(scanf("%d %d",&n,&k)==2&&n&&k){
> 		int i,vv;
> 		int sum=0;
> 		table[0].first=0;table[0].second=0;
> 		for(i=1;i<=n;i++){
> 			scanf("%d",&vv);
> 			sum+=vv;
> 			table[i].first=sum;
> 			table[i].second=i;
> 		}
> 		n++;
> 		sort(table,table+n);
> 		int t;
> 		for(i=0;i<k;i++){
> 			scanf("%d",&t);
> 			Solve(t);
> 		}
> 	}
> }

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