ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1971. Graphics Settings

test 6: Runtime error (access violation), what can it be?
Posted by Abram_TA 8 Aug 2013 02:22
Here is my not accepted solution:
#include<iostream>
#include<string>
using namespace std;

double P(int power[],string names[],int a,int n,int video_power,int on_or_off[],int w,int h){
a=video_power;
for(int i=0;i<n;i++){if(on_or_off[i]==1){a/=power[i];}}
double res=a/(w*h);
return res;
}

int main()
{

int n;
cin>>n;
string * names = new string[n];
int * power = new int[n];
for (int i=0;i<n;i++){
cin>>names[i];
cin>>power[i];
}

int w,h,video_power;
cin>>w>>h>>video_power;

double results[100];
int on_or_off[100];
for(int i=0;i<n;i++){on_or_off[i]=1;}
int e=0;

int a=video_power;
for (int i=0; i<n;i++){
a/=power[i];
}
double prodyctivity=a/(w*h);
results[e]=prodyctivity;e++;

int m;
cin>>m;
for(int i=0; i<m; i++){
string change,change_name;
cin>>change;
if(change[0]!='R'){
cin>>change_name;
for(int y=0;y<n;y++){
if(change=="On" && change_name==names[y]){
on_or_off[y]=1;
prodyctivity=P(power,names,a,n,video_power,on_or_off,w,h);
results[e]=prodyctivity;e++;
}
else if(change=="Off" && change_name==names[y]){
on_or_off[y]=0;
prodyctivity=P(power,names,a,n,video_power,on_or_off,w,h);
results[e]=prodyctivity;e++;
}
}
}
else{
int a1,a2;
cin>>a1>>a2;
w=a1;h=a2;
prodyctivity=P(power,names,a,n,video_power,on_or_off,w,h);
results[e]=prodyctivity;e++;
}
}

for(int i=0;i<m+1;i++){
if(results[i]<10){cout<<"Slideshow"<<endl;}
else if(results[i]>=60){cout<<"Perfect"<<endl;}
else{cout<<"So-so"<<endl;}
}
}