1101 - s2 = s1 - wage[j]; for(k=j-1; k>=0; k--){...

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&gt;=0; k--){ if(k==i) continue; s3 = s2 - wage[k]; if(s3 &lt; wage[0] || s3&gt;wage[num-1]) continue; p = (int*)bsearch(&amp;s3, wage, num, sizeof(int), (int (*)(const void*, const void*))cmp); if(p != NULL){ ret = p - wage; if(ret != i &amp;&amp; ret!=j &amp;&amp; ret!=k) return i; } } } } return -1; } int main(){ int t; scanf(&quot;%d&quot;,&amp;num); while(num &gt; 0){ readIn(); t = fun(); if(t &gt;= 0){ printf(&quot;%d\n&quot;, wage[t]); } else { printf(&quot;no solution\n&quot;); } scanf(&quot;%d&quot;,&amp;num); } return 0; }...
View Full Document

Page1 / 2

1101 - s2 = s1 - wage[j]; for(k=j-1; k&amp;amp;gt;=0; k--){...

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