Pagini recente » Cod sursa (job #1930198) | Cod sursa (job #3225400) | Cod sursa (job #2500602) | Cod sursa (job #2173683) | Cod sursa (job #2204636)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("aprindere.in");
ofstream fout("aprindere.out");
float a[1001],v[1010][1010],timp,maxim,nrstinse,nraprinse,nrminstinse,nrmaxaprinse,t,minim;
int indice,i,j,n,m;
int main()
{
fin>>n>>m;
for(i=1;i<=n;i++)
fin>>a[i];
for(i=1;i<=m;i++)
{
fin>>v[i][1]>>v[i][2]>>v[i][3];
for(j=1;j<=v[i][3];j++)
{
fin>>v[i][j+3];
v[i][j+3]++;
}
v[i][1]++;
}
bool ok=1;
for(i=1;i<=n&&ok;i++)
if(a[i]==0)
ok=0;
while(ok==0)
{
ok=1;
maxim=0;
t=0;
indice=0;
minim=10000000000;
for(i=1;i<=m;i++)
{
nraprinse=0;
nrstinse=0;
for(j=1;j<=v[i][3];j++)
{
if(a[(int)v[i][j+3]]==0&&v[i][j+3]!=v[i][1])
nraprinse++;
else if(v[i][j+3]!=v[i][1])
nrstinse++;
}
if(a[(int)v[i][1]]==0)
nraprinse++;
else
nrstinse++;
/*float raport=nraprinse/v[i][2];
if(raport>maxim)
{
maxim=raport;
indice=i;
t=v[i][2];
}*/
if(nraprinse>maxim)
{
maxim=nraprinse;
t=v[i][2];
indice=i;
minim=nrstinse;
}
else if(nraprinse==maxim&&nrstinse<minim)
{
maxim=nraprinse;
t=v[i][2];
indice=i;
minim=nrstinse;
}
else if(nraprinse==maxim&&nrstinse==minim&&v[i][2]<t)
{
maxim=nraprinse;
t=v[i][2];
indice=i;
minim=nrstinse;
}
}
timp+=t;
for(j=1;j<=v[indice][3];j++)
a[(int)v[indice][j+3]]=!a[(int)v[indice][j+3]];
for(i=1;i<=n;i++)
if(a[i]==0)
ok=0;
}
fout<<timp;
return 0;
}