1101 - s2 = s1 wage[j for(k=j-1 k>=0 k if(k==i continue...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<cstdio> #include<cstdlib> using namespace std; enum { SIZ = 1004, }; int num; int wage[SIZ]; // small first; int cmp(const int*a, const int*b){ return *a - *b; } void readIn(){ for(int i=0;i<num;i++){ scanf("%d",&wage[i]); } qsort(wage, num, sizeof(int), (int (*)(const void*, const void*))cmp); } int fun(){ int ret = -1; int i,j,k; int s1,s2,s3; int *p; for(i=num-1;i>=0;i--){ // 注æ1‚ j + k + x = i汶Ri崯貽岨min(j,k,x)å²²max(j,k,x)ä¹1铵 s1 = wage[i]; for(j=num-1; j>=1;j--){ if(j==i) continue;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: s2 = s1 - wage[j]; for(k=j-1; k>=0; k--){ if(k==i) continue; s3 = s2 - wage[k]; if(s3 < wage[0] || s3>wage[num-1]) continue; p = (int*)bsearch(&s3, wage, num, sizeof(int), (int (*)(const void*, const void*))cmp); if(p != NULL){ ret = p - wage; if(ret != i && ret!=j && ret!=k) return i; } } } } return -1; } int main(){ int t; scanf("%d",&num); while(num > 0){ readIn(); t = fun(); if(t >= 0){ printf("%d\n", wage[t]); } else { printf("no solution\n"); } scanf("%d",&num); } return 0; }...
View Full Document

This note was uploaded on 02/18/2010 for the course CS 100 taught by Professor Acm during the Spring '10 term at Zhejiang University.

Page1 / 2

1101 - s2 = s1 wage[j for(k=j-1 k>=0 k if(k==i continue...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online