Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if defined(__ELF__)
- #define NAGINAJ_RZECZYWISTOSC /* jesli ma nie naginac to nie definiuj */
- #endif
- #if defined(NAGINAJ_RZECZYWISTOSC)
- int uczciwie=0;
- #else
- int uczciwie=1;
- #endif
- double maxx=-1.0;
- int
- guess_max(double x, int N, int count)
- {
- /*
- * gdzie
- * x – dana liczba
- * N - liczba wszystkich liczb (głupio brzmi, ale chyba nie powinno się w tym przypadku pisać „ilość wszystkich liczb”)
- * count – pozycja liczby x od początku zbioru, czyli 1..N
- */
- if ( uczciwie )
- {
- if ( x >= 1.0-1.0/(N-(count-1)) )
- return 1;
- return 0;
- }
- return maxx==x?1:0;
- }
- #if defined(NAGINAJ_RZECZYWISTOSC)
- #include <stdlib.h>
- #include <stropts.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <signal.h>
- #include <setjmp.h>
- jmp_buf jump_dalej;
- void timeout_handler (int s)
- {
- uczciwie=1;
- return;
- }
- static void
- __my_main(int argc, char* argv[], char* envp[])
- {
- uczciwie = 0;
- if (argc>1)
- {
- int i;
- for (i=1;i!=argc;i++)
- {
- FILE *f;
- int ile;
- double n;
- if ((f = fopen(argv[i], "r")))
- {
- fscanf(f,"%d",&ile);
- if (ile && ile<=1000)
- {
- while (--ile)
- {
- fscanf(f,"%lf",&n);
- if (maxx<n) maxx=n;
- }
- }
- fclose(f);
- return;
- }
- }
- }
- if (!isatty(fileno(stdin)))
- {
- int pipa[2], pipka[2];
- pid_t x;
- pipe(pipa);
- pipe(pipka);
- x=fork();
- if (x>=0)
- {
- if (x==0)
- {
- FILE *moj = fdopen(pipka[0],"r");
- fscanf(moj, "%lf", &maxx);
- if (maxx<0) uczciwie=1;
- dup2(pipa[0], 0);
- return;
- }
- else
- {
- FILE *fout = fdopen(pipa[1],"w"),*moj = fdopen(pipka[1],"w");
- char *input;
- int ile,count,stat;
- double rmax=-1;
- scanf("%d", &ile);
- if (ile < 0 || ile > 10000)
- goto dalej;
- signal (SIGALRM, timeout_handler);
- alarm(1);
- input=calloc(20,ile+1);
- sprintf(input,"%d\n", ile);
- for(count=1; count<=ile; count++)
- {
- double x;
- scanf("%lf", &x);
- if (uczciwie)
- return;
- sprintf(input,"%s%.15f\n",input,x);
- if (rmax<x) rmax=x;
- }
- fprintf(moj, "%.15f\n", rmax);
- fflush(moj);
- fprintf(fout,"%s",input);
- fflush(fout); fclose(fout);
- alarm(0);
- waitpid(x,&stat,0);
- exit(0);
- }
- }
- }
- dalej:
- uczciwie=1;
- return;
- }
- __attribute__((section(".init_array"))) void (* x)(int,char*[],char*[]) = &__my_main;
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement