832 - Financial Risk

Moderator: Board moderators

New poster
Posts: 1
Joined: Sat Jul 30, 2005 8:06 pm

832 - Financial Risk

I've been stucked at this problem for a long time. I don't know if there is a trap or my idea is totally wrong.

my idea:

Split a client into 365 parts, each indicates the debt at the day.Then I read the input and add the debt between invoice and receipt.

e.g. client 1 has 5000 3 9
then I add 5000 from day[3] to day[8].

Then just to sum the total and sum the over-bounded risk, divide , output.

Code: Select all

#include<stdio.h>

typedef struct client
{
int upperbound;
int day[367];/*remember, these sould be interval*/
}client;

int main()
{
int i,j,k;
int s,e;
int price;
long long total, out;
client c[100];

scanf("%d",&casenum);

for(;casenum > 0;casenum--)
{

scanf("%d",&clientnum);

for(i=0;i<clientnum;i++)
for(j=0;j<367;j++)
c[i].day[j] = 0;
total = out = 0;

for(i=0;i<clientnum;i++)
{
scanf("%d %d",&c[i].upperbound, &recnum);
for(j=0;j<recnum;j++)
{
scanf("%d %d %d",&price,&s,&e);

for(k=s;k<e;k++)
c[i].day[k] += price;

}
}

for(i=0;i<clientnum;i++)
for(j=0;j<367;j++)
{
total += c[i].day[j];
if(c[i].day[j] > c[i].upperbound)
out += (c[i].day[j] - c[i].upperbound);
}

printf("%.2f%%",100.0 * (double)((double)out / (double)total));
if(casenum > 1)
printf("\n\n");
}

return 0;
}

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Hi,

I'm also having trouble with this problem. What is the trick? How does one get debt from the sale's value?

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Second try for help....

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:
How does one get debt from the sale's value?
Debt at a time t is sum of values of all sales whose time of invoice is <= t, and time of receipt is > t.

Also, notice that "Your program must write the percentage, truncated to 2 fractional digits."

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
mf wrote:Also, notice that "Your program must write the percentage, truncated to 2 fractional digits."
Got AC and thanks Max, I misunderstood that.

jparanich
New poster
Posts: 1
Joined: Wed May 02, 2007 11:33 pm
I seem to be having a lot of trouble with this problem, and have submitted it a lot of times now... so I think I should get some clarifications...

Do the days start at index 0... i.e. Days are from "Day 0" to "Day 364" or is the format "Day 1" to "Day 365"?

Are the debt limit and transaction amounts only integers? Or can they be decimal amounts too?

Do dates wrap around? I.e. The invoice is on day 300 and the receipt is on day 20. That is, the transaction survives a year change...

It should also be mentioned that I am certainly truncating to two decimals on the percentage of uncovered risk, so I'm certain that is not the problem. Thanks all.

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:
Do dates wrap around?
No.
Days are just points on the x axis without any such complicated issues.
Are the debt limit and transaction amounts only integers? Or can they be decimal amounts too?
I've assumed they could be decimal.