Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

A Solution For The "Hartals" Problem

DZone's Guide to

A Solution For The "Hartals" Problem

·
Free Resource
A solution for the "Hartals" problem.

Problem description:
http://icpcres.ecs.baylor.edu/onlinejudge/external/100/10050.html

Author: Joana Matos Fonseca da Trindade
Date: 2008.04.06


/* 
 * Solution for the "Hartals" problem.
 * UVa ID: 10050
 */
#include 
  
   
 
#define NDAYS 3651
 
using namespace std;

/* simulation time (in days) */
int st[NDAYS]; 
 
/* main */
int main (int argc, const char *argv[]) {
	int nc; /* number of cases */
	int nd; /* number of days */
	int np; /* number of political parties */
	int h; /* current hartal number */
	int dl;	/* days lost */
	
	cin >> nc;
	
	/* for each case.. */
	for (int i=0; i
   
    > nd;
		cin >> np;		
		
		/* initialize simulation table */
		for (int j=0; j<=nd; j++) {
			st[j] = 0;
		}
		dl = 0; /* init days lost counter */
		
		/* update with hartal for each party */
		for (int j=0; j
    
     > h;
			for (int k=1; k*h-1<=nd; k++) {
				st[k*h-1] = 1; /* set lost day flag */
			}
		}
		
		/* calculate number of days lost */
		for (int j=0; j
     
    
   
  
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}