12148 - Electricity

Moderator: Board moderators

Devil_Bird
New poster
Posts: 10
Joined: Sun Mar 17, 2013 12:02 am

12148 - Electricity

actually I used the simplest algorithm but It gets WA help plz

Code: Select all

``````#include<iostream>
using namespace std;

struct data{
int d;
int m;
int y;
long long int c;
}MI[1009];
int main()
{
int N;
while(cin>>N && N!=0)
{
for(int i=0;i<N;i++)
cin>>MI[i].d>>MI[i].m>>MI[i].y>>MI[i].c;
int res=0,cd=0;
for(int i=0;i<N-1;i++)
{
if(MI[i].y==MI[i+1].y)
{
if(MI[i].m==MI[i+1].m)
{
if((MI[i].d+1)==MI[i+1].d)
{res+=MI[i+1].c-MI[i].c;cd++;continue;}
}
else
{
if(MI[i+1].m==(MI[i].m+1) || (MI[i].m==12 && MI[i+1].m==1))
{
if(MI[i].m==2)
{
if(MI[i].y%4==0 && MI[i].y%100!=0)
{
if(MI[i].d==29 && MI[i+1].d==1)
{res+=MI[i+1].c-MI[i].c;cd++;continue;}
}
else
if(MI[i].d==28 && MI[i+1].d==1)
{res+=MI[i+1].c-MI[i].c;cd++;continue;}

}
else
if(MI[i].m<7)
{
if(MI[i].m%2==0)
{
if( MI[i].d==30 && MI[i+1].d==1)
{res+=MI[i+1].c-MI[i].c;cd++;continue;}
}
else
if(MI[i].d==31 && MI[i+1].d==1)
{res+=MI[i+1].c-MI[i].c;cd++;continue;}
}

else
{
if(MI[i].m==7 && MI[i].d==31 && MI[i+1].d==1)
{res+=MI[i+1].c-MI[i].c;cd++;continue;}
if(MI[i].m%2==0)
{
if( MI[i].d==31 && MI[i+1].d==1)
{res+=MI[i+1].c-MI[i].c;cd++;continue;}
}
else
if(MI[i].d==30 && MI[i+1].d==1)
{res+=MI[i+1].c-MI[i].c;cd++;continue;}
}
}
}
}
else
{
if(MI[i+1].y==(MI[i].y+1) && MI[i].m==12 && MI[i+1].m==1 && MI[i].d==31 && MI[i+1].d==1)
{res+=MI[i+1].c-MI[i].c;cd++;}
}
}
cout<<cd<<" "<<res<<endl;
}
}``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12148 - Electricity WA

Input:

Code: Select all

``````2
28 2 2000 0
1 3 2000 1
0
``````
AC output:

Code: Select all

``0 0``
Check input and AC output for thousands of problems on uDebug!

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 12148 - Electricity WA

brianfry713,

Thanks for sharing this test case.

Devil_Bird,

This post is in the wrong forum. The least you could do when creating a new thread is to check that it's in the right place.
Check input and AC output for over 7,500 problems on uDebug!

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am

Re: 12148 - Electricity

I didn't understand this:
the number of days for which a consumption can be precisely determined
Can anybody, please explain it clearly?
And how the sample output is come from the sample input ? Please, explain it also...
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
Email me: shahidul.cse.brur@gmail.com

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12148 - Electricity

You are looking for consecutive days

Code: Select all

``````29 10 1979 458
30 10 1979 470
...
1 11 1979 480
2 11 1979 483
Case 1: 2 consecutive days, total consumption = (470 - 458) + (483 - 480)

Case 2: No consecutive days

28 2 1978 112
1 3 1978 113
...
14 11 2008 600
15 11 2008 790
Case 3: 2 consecutive days, total consumption = (113 - 112) + (790 - 600)
``````
Check input and AC output for thousands of problems on uDebug!

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am

Re: 12148 - Electricity

Thank you, now I got it.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
Email me: shahidul.cse.brur@gmail.com

anacharsis
Learning poster
Posts: 69
Joined: Mon Feb 09, 2015 1:56 am

Re: 12148 - Electricity

In:

Code: Select all

``````4
28 2 2000 600
29 2 2000 700
1 3 2000 800
2 3 2000 900
0
``````
AC out:

Code: Select all

``````3 300
``````

Fibonacci_Prower
New poster
Posts: 3
Joined: Fri Jan 18, 2008 8:52 pm

Re: 12148 - Electricity

This gets me WA:

Code: Select all

``````#include <iostream>
#include <ctime>

using namespace std;

int main(void) {
int N;
struct tm dato;
dato.tm_sec=dato.tm_min=dato.tm_hour=dato.tm_mday=dato.tm_mon=dato.tm_year=dato.tm_wday=dato.tm_yday=dato.tm_isdst=0;
const time_t secondsperday = 86400;
while((cin >> N) && N) {
int totalconsumption = 0, preading = 0, reading = 0, days = 0;
while(N--) {
time_t previoustime = mktime(&dato);
cin >> dato.tm_mday >> dato.tm_mon >> dato.tm_year >> reading;
dato.tm_year -= 1900;
--dato.tm_mon;
if(mktime(&dato)-previoustime == secondsperday) {
++days;
}
}
cout << days << ' ' << totalconsumption << endl;
}
return 0;
}``````
This, on the other hand, is accepted (see the only line with a comment):

Code: Select all

``````#include <iostream>
#include <ctime>

using namespace std;

int main(void) {
int N;
struct tm dato;
dato.tm_sec=dato.tm_min=dato.tm_hour=dato.tm_mday=dato.tm_mon=dato.tm_year=dato.tm_wday=dato.tm_yday=dato.tm_isdst=0;
const time_t secondsperday = 86400;
while((cin >> N) && N) {
int totalconsumption = 0, preading = 0, reading = 0, days = 0;
while(N--) {
time_t previoustime = mktime(&dato);
cin >> dato.tm_mday >> dato.tm_mon >> dato.tm_year >> reading;
dato.tm_year -= 1900;
--dato.tm_mon;

dato.tm_hour=dato.tm_isdst=0; //Why is this value even changing?

if(mktime(&dato)-previoustime == secondsperday) {