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 |
总是runtime error,大家帮看看啊#include <iostream> #define NUM 80000 #define MAXX 100000 using namespace std; long data_pos[NUM][3]; int data_value[NUM]; long res_num[MAXX]; int res_value[MAXX]; int pair_num = 0; int len = 0; int res_len = 0; void single_process(int i1, long i2); int main() { int value; long num; long pos = 0; while(cin>>len) { pos = 0; res_len = 0; pair_num = 0; if(len == 0) break; while(cin>>value>>num) { if(value == 0 && num ==0) break; ////////数据输入/////////// data_pos[pair_num][0] = pos; pos = pos + num; data_pos[pair_num][1] = pos - 1; data_pos[pair_num][2] = num; data_value[pair_num] = value; pair_num ++; } //cout<<"last:"<<data_pos[pair_num-1][1]<<endl; ////////数据处理/////////// long cur_pos = 0; for(int i1 = 0; i1 < pair_num; i1++) { //无法简化 if(data_pos[i1][2] < (4 * len - 1)) { //逐个处理 for(long i2 = data_pos[i1][0]; i2 <= data_pos[i1][1]; i2++) { single_process(i1, i2); cur_pos ++; } } //可以集团简化处理 else { //先处理首部 long pos11 = long(long(cur_pos / len) + 2); long stage1 = long(pos11 * len - 1); for(long i = data_pos[i1][0]; i <= stage1; i++) { single_process(i1, i); //cur_pos ++; } //处理中部 long stage2 = long((data_pos[i1][1]/len - 1)*len -1); res_num[res_len] = stage2 - stage1; res_value[res_len] = 0; res_len ++; //cur_pos += data_pos[i1][] //处理尾部 long stage3 = data_pos[i1][1]; for(long j = stage2 + 1; j <= stage3; j++) single_process(i1, j); cur_pos += data_pos[i1][2]; } } /////合并处理 int temp_value = res_value[0]; long temp_num = 0; cout<<len<<endl; //cout<<"res_len:"<<res_len<<endl; for(int count = 0; count < res_len; count++) { if(res_value[count] == temp_value) { temp_num += res_num[count]; } else { cout<<temp_value<<" "<<temp_num<<endl; temp_value = res_value[count]; temp_num = 1; } } cout<<temp_value<<" "<<temp_num<<endl; cout<<"0"<<" "<<"0"<<endl; } cout<<"0"<<endl; return 0; } void single_process(int i1, long i2) { //pos1 int max = 0; long pos1 = i2 - len - 1; int temppos; int val; if(pos1 >= 0 && i2 % len != 0) { temppos = i1; while(data_pos[temppos][0] > pos1) temppos --; val = abs(data_value[temppos] - data_value[i1]); if(val > max) max = val; } //cout<<"f1"<<endl; //cout<<"pos1:"<<max<<endl; //pos2 pos1 = i2 - len; if(pos1 >= 0) { temppos = i1; while(data_pos[temppos][0] > pos1) temppos --; val = abs(data_value[temppos] - data_value[i1]); if(val > max) max = val; } //cout<<"f2"<<endl; //cout<<"pos2:"<<max<<endl; //pos3 pos1 = i2 - len + 1; if(pos1 >= 0 && (i2 + 1) % len != 0) { temppos = i1; while(data_pos[temppos][0] > pos1) temppos --; val = abs(data_value[temppos] - data_value[i1]); if(val > max) max = val; } //cout<<"f3"<<endl; //cout<<"pos3:"<<max<<endl; //pos4 pos1 = i2 - 1; if(pos1 >= 0 && i2 % len != 0) { temppos = i1; while(data_pos[temppos][0] > pos1) temppos --; val = abs(data_value[temppos] - data_value[i1]); if(val > max) max = val; } //cout<<"f4"<<endl; //cout<<"pos4:"<<max<<endl; //pos5 pos1 = i2 + 1; if(pos1 <= data_pos[pair_num - 1][1] && (i2 + 1) % len != 0) { temppos = i1; while(data_pos[temppos][1] < pos1) temppos ++; val = abs(data_value[temppos] - data_value[i1]); if(val > max) max = val; } //cout<<"pos5:"<<max<<endl; //pos6 //cout<<"f5"<<endl; pos1 = i2 + len -1; if(pos1 <= data_pos[pair_num - 1][1] && i2 % len != 0) { temppos = i1; while(data_pos[temppos][1] < pos1) temppos ++; val = abs(data_value[temppos] - data_value[i1]); if(val > max) max = val; } //cout<<"pos6:"<<max<<endl; //pos7 //cout<<"f6"<<endl; pos1 = i2 + len; if(pos1 <= data_pos[pair_num - 1][1]) { temppos = i1; while(data_pos[temppos][1] < pos1) temppos ++; //if(res_len == 31)cout<<"datavale:"<<pos1<<endl; val = abs(data_value[temppos] - data_value[i1]); if(val > max) max = val; } pos1 = i2 + len + 1; if(pos1 <= data_pos[pair_num - 1][1] && (i2 + 1) % len != 0) { temppos = i1; while(data_pos[temppos][1] < pos1) temppos ++; val = abs(data_value[temppos] - data_value[i1]); if(val > max) max = val; } res_num[res_len] = 1; res_value[res_len] = max; res_len ++; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator