Pagini recente » Cod sursa (job #2404802) | Cod sursa (job #721158) | Cod sursa (job #1825184) | Cod sursa (job #46255) | Cod sursa (job #1470325)
#include <stdio.h>
#include <string.h>
#define NMAX 30005
#define SIZE 150005
int N, L, U;
short int cost[NMAX], time[NMAX];
int i, j, cost_sum[NMAX], time_sum[NMAX], S1, S2, s1, s2, len;
long long int a1, a2;
FILE *in, *out;
float rez;
char string[SIZE];
void citire()
{
in = fopen("secv3.in", "r");
out = fopen("secv3.out", "w");
fscanf(in, "%d %d %d\n", &N, &L, &U);
fgets(string, SIZE - 1, in);
len = strlen(string) - 1;
i = 1;
for (j = 0; j < len; j++, i++)
{
while (string[j] >= '0' && string[j] <= '9')
cost[i] = cost[i]*10 + string[j++]-'0';
/*
* cost_sum[i] = cost[1] + cost[2] + ... + cost[i]
* Obs. : cost_sum[i] - cost_sum[j] = cost[j+1] + ... + cost[i], ptr i >= j+1
*/
cost_sum[i] = cost_sum[i-1] + cost[i];
}
fgets(string, SIZE - 1, in);
len = strlen(string) - 1;
i = 1;
for (j = 0; j < len; j++, i++)
{
while (string[j] >= '0' && string[j] <= '9')
time[i] = time[i]*10 + string[j++]-'0';
/* analog cost_sum[] */
time_sum[i] = time_sum[i-1] + time[i];
}
}
int main()
{
citire();
//print();
S1 = 0;
S2 = 1;
for (i = L; i <= U; i++) //i = seq len
for (j = i; j <= N; j++)
{
a1 = S1; a1 *= (s2 = time_sum[j]-time_sum[j-i]);
a2 = S2; a2 *= (s1 = cost_sum[j]-cost_sum[j-i]);
if (a1 < a2)
S1 = s1, S2 = s2;
}
fprintf(out, "%.2f\n", (float)((float)S1)/((float)S2));
fclose(in);
fclose(out);
return 0;
}