Esempio n. 1
0
void gen_euclid(int n)
{
    int g = a[0];
    FOR(i,1,n) g = euclid(g, a[i], X[i], Y[i]);
    LL mult = 1;
    FORD(i,n,1) v[i] = (mult * Y[i]) % m, mult = (mult * X[i]) % m;
    v[0] = mult;
}
Esempio n. 2
0
int main(void){
	for(int snum = 1; scanf("%d",&n) && n; ++snum){
		FOR(i, n) scanf("%d %d",&p[i].x,&p[i].y);
		printf("Scenario #%d\n",snum);
		printf("Frog Distance = %.3lf\n\n",sqrt(dijkstra(0,1)));
	}
	return 0;
}
Esempio n. 3
0
void imprimir_tablero() {
    int i, j;

    printf("\n   ");
    FOR (j)
        printf("%d ", j);
    printf("\n");
    printf("  +---------------+\n");

    FOR (i) {
        printf("%c |", 'a' + i);
        FOR (j)
            printf("%c ", tablero[i][j]);
        printf("\b|\n");
    }
    printf("  +---------------+\n");
}
Esempio n. 4
0
int main(void){
	int n; scanf("%d", &n);
	for(int m, s; n-- && scanf("%d %d", &s, &m) == 2; ){
		int maxv = 0;
		FOR(i, m) scanf("%d", &v[i]), maxv = max(maxv, v[i]);
		FOR(i, s + maxv) dp[i] = 0x3fffffff;
		dp[0] = 0;
		FOR(i, m) for(int j = s + maxv; j >= v[i]; --j)
			dp[j] = min(dp[j], dp[j - v[i]] + 1);
		FORI(i, s, s + maxv + 1)
			if(dp[i] < 0x3fffffff){
				printf("%d %d\n", i, dp[i]);
				break;
			}
	}
	return 0;
}
Esempio n. 5
0
 void bcc() {
     FOR(i,1,N+1) par[i] = disc[i] = low[i] = -1;
     FOR(i,1,N+1) if (disc[i] == -1) {
         BCCutil(i);
         if (sz(st)) fin.pb(st);
         st.clear();
     }
 }
Esempio n. 6
0
int main()
{
	int i,T,n,m=0;
    ll A[MAX];
    ll B[MAX];
    scanf("%d",&T);
    while(T--){
    	m=0;
    	IN(n);
    	FOR(i,n)
    		IN(A[i]);
    	FOR(i,n)
    		IN(B[i]);
    	FOR(i,n)
    		m=max(m,monkiness(B,A[i],n)-i);	
    	printf("%d\n",m);    	
    }
}
Esempio n. 7
0
long long int reverse(long long int n) {
    int c = 0;
    while (n > 0) {
        digits[c++] = n % 10;
        n /= 10;
    }
    FOR(j, c) n = n * 10 + digits[j];
    return n;
}
Esempio n. 8
0
// _num: #particles 
void binning(particle_t* _particles, bin_t* _bins, int _num) {
	FOR (i, numBins)
		_bins[i].num_particles = 0;

	FOR (i, _num) {
		int id = globalIds[i];
		_bins[id].particle_ids[_bins[id].num_particles] = i;
		_bins[id].num_particles++;
	}
Esempio n. 9
0
int main()
{
	// Test cases
	TC0;

	// String to binary converter
	StringBinaryConverter to_binary_converter;

	to_binary_converter.Reserve(1024);

	String test_string("HelloWorldStringConverter");

	FOR(100)
		to_binary_converter.Register(test_string);
	
	FOR(200)
		to_binary_converter.Remove(0);
}
Esempio n. 10
0
File: mm2.c Progetto: gburd/wool
TASK_2(int, main, int, argc, char**, argv) {
  int i,j,ok;
  double *a,*b,*c;
  int rows, bs;

  /* Decode arguments */

  if(argc < 3) {
    fprintf(stderr, "Usage: %s [wool options] <matrix rows> <blocksize>\n", argv[0]);
    exit(1);
  }
  rows = atoi(argv[1]);
  bs = atoi(argv[2]);

  printf( "%d rows, blocksize %d\n", rows, bs );



  /* Allocate and initialize matrices */

  a = (double *) malloc(rows*rows*sizeof(double));
  b = (double *) malloc(rows*rows*sizeof(double));
  c = (double *) malloc(rows*rows*sizeof(double));

  for( i=0; i<rows; i++ ) {
    for( j=0; j<rows; j++ ) {
      a[i*rows+j] = 0.0;
      b[i*rows+j] = 0.0;
    }
    a[i*rows+i] = 1.0;
    b[i*rows+i] = 1.0;
  }


  /* Multiply matrices */

  FOR( mm, 0, (rows+bs-1)/bs, rows, bs, a, b, c );

  /* Check result */

  ok = 1;
  for( i=0; i<rows; i++ ) {
    for( j=0; j<rows; j++ ) {
      if( i!=j && c[i*rows+j] != 0.0 ) {
        ok = 0;
      }
      if( i==j && c[i*rows+j] != 1.0 ) {
        ok = 0;
      }
    }
  }

  printf("Ok: %d\n", ok);
  return 0;

}
Esempio n. 11
0
  FOR (i, FEATURES) {

    float *pf = pS, xi=x[i], s=0, *px=x;

    FOR (j, i) s += (*pf++) * (*px++);

    su += (s + 0.5 * (*pf) * xi + (*pT++)) * xi; 

    pS += FEATURES;
  }
int main(void) {
    int t;
    scanf("%d", &t);
    FOR(tt, t) {
        scanf("%d%d", &n, &m);
        FOR(i, n) {
            char row[MAXN];
            scanf("%s", row);
            FOR(j, m) data[i][j] = row[j] == '1';
        }
Esempio n. 13
0
int main(void){
	int m, n;
	for(RI(n), RI(m); (m || n); RI(n), RI(m)){
		int a, ans = 0, b, maxppa = MINPPA, ppa;
		FOR(i, n) cnt[i] = 0, p[i] = i;
		FOR(i, n) FORI(j, i + 1, n) adj[i][j] = MINPPA;
		FOR(i, m){
			RI(a), RI(b), RI(ppa);
			--a; --b;
			if(a > b) swap(a, b);
			if(ppa > adj[a][b]){
				adj[a][b] = ppa;
				maxppa = max(maxppa, ppa);				
			}
		}
		FOR(i, n) FORI(j, i + 1, n) if(adj[i][j] == maxppa) unionfind(i, j);
		FOR(i, n) ans = max(ans, ++cnt[findroot(i)]);
		printf("%d\n", ans);
	}
Esempio n. 14
0
void Feature::asc_write(FILE *fp)
{
  int i, k;
  
  FOR (k, bucket_num) {
    
    fprintf(fp, "%2d ", k);
    FOR (i, Entry::INTERVAL_NUM) fprintf(fp, " %+6.3f", entries[k].get_y(i));
    fprintf(fp, "\n");
  }
Esempio n. 15
0
int main(void){
	for(int c, h, w, x, y, x2, y2, E, G; scanf("%d %d", &w, &h) == 2 && w; ){
		ecnt = 0;
		FOR(i, w) FOR(j, h) board[i][j] = 0, d[mask(i, j)] = INF;
		board[w - 1][h - 1] = 'E';
		d[0] = 0;
		// Read Gravestones
		scanf("%d", &G);
		FOR(i, G){
			scanf("%d %d", &x, &y);
			board[x][y] = 'G';
		}
		// Read Haunted Holes
		scanf("%d", &E);
		FOR(i, E){
			scanf("%d %d %d %d %d", &x, &y, &x2, &y2, &c);
			add_edge(mask(x, y), mask(x2, y2), c);
			board[x][y] = 'E';
		}
Esempio n. 16
0
int main(void){
	for(char app[1024], m[1024]; ; ){
		char x; int app_cnt, n, t = 0;
		FOR(i, 10) ans[i] = '_'; ans[10] = 0;
		FOR(i, 26) c[i] = 0;
		FOR(i, 10) FOR(j, 26) cr[i][j] = false;
		solved = false;
		for(app_cnt = 0; gets(app) && *app; ++app_cnt){
			sscanf(app, " %c%d %s", &x, &n, m);
			t += c[x -= 'A'] = n;
			for(int i = 0; m[i] != ';'; ++i) cr[m[i] - '0'][x] = true;
		}
		if(!app_cnt) break;
		solved = false;
		bt(0, t);
		if(solved) puts(ans);
		else puts("!");
	}
	return 0;
}
Esempio n. 17
0
T3::Scalar T3::Axisymmetric::operator*(const T3::Vector& x) const {
    Scalar dx;
    dx += at(0)(x[0]);

    Field dxu = at(1)(x[1]);
    PFOR(i,x.N[0]) FOR(j,x.N[1]) dxu(i,j,0) /= at(0)(i);
    dx += dxu;
    
    Field xu = x[0];
    PFOR(i,x.N[0]) FOR(j,x.N[1]) xu(i,j,0) /= at(0)(i) / 2.;
    dx += xu;
    
    xu = x[1];
    PFOR(i,x.N[0]) FOR(j,x.N[1]) xu(i,j,0) /= at(0)(i) * sin( at(1)(j) ) / cos( at(1)(j) );
    dx += xu;
    
    dx.parent = x.parent;
    dx.fix();
    return dx;
}
Esempio n. 18
0
T3::Scalar T3::Axisymmetric::Lap(const T3::Scalar& x) const {
    Scalar dx;
    dx += at(0).two(x);
    
    Field dux = at(1).two(x);
    PFOR(i,x.N[0]) FOR(j,x.N[1]) dux(i,j,0) /= at(0)(i)*at(0)(i);
    dx += dux;
    
    dux = at(0)(x);
    PFOR(i,x.N[0]) FOR(j,x.N[1]) dux(i,j,0) /= at(0)(i)/2;
    dx += dux;
    
    dux = at(1)(x);
    PFOR(i,x.N[0]) FOR(j,x.N[1]) dux(i,j,0) /= at(0)(i)*at(0)(i)*sin(at(1)(j))/cos(at(1)(j));
    dx += dux;
    
    dx.parent = parent;
    dx.fix();
    return dx;
}
Esempio n. 19
0
bool NewGame::f_write_packed(FILE *fp)
{
  fputc(get_flags(), fp);
  fputc(get_move_num(), fp);
  fputc(get_value(), fp);

  int i;

  FOR (i, get_move_num()) fputc(get_pm(i).get_raw(), fp);

  return !ferror(fp);
}
Esempio n. 20
0
int main() {
  FOR(i,0,N-1) a[i]=b[i]=i;

  LDCL ldcl;
  ldcl.loadFunc("kernal.cl","adder",cl::NDRange(N),cl::NDRange(1024));
  ldcl.setArg(a, N*sizeof(a[0]), CL_MEM_READ_ONLY);
  ldcl.setArg(b, N*sizeof(b[0]), CL_MEM_READ_ONLY);
  ldcl.setArg(c, N*sizeof(b[0]), CL_MEM_READ_WRITE, LDCL_NEED_READ);
  long long tt=clock();
  ldcl.run();
  cout<<clock()-tt<<endl;
}
Esempio n. 21
0
int greedy_match(int n)  {
	int ans=0;
	FOR1(i,n)if(mh[i]==0)
		FOR(j,G[i].size())
			if(mh[G[i][j]]==0) {
				mh[G[i][j]]=i;
				mh[i]=G[i][j];
				ans++;
				break;
			}
	return ans;
}
Esempio n. 22
0
int main(void){
	while(scanf("%d%d", &n, &v) == 2){
		int min_cap = 0, u, v, w;
		FOR(i, n) scanf("%d", z + i), min_cap = max(min_cap, z[i]);
		for(u = min_cap, v = MAXC; u < v; ){
			w = (u + v) >> 1;
			if(!possible(w)) u = w + 1;
			else v = w;
		}
		printf("%d\n", u);
	}
	return 0;
}
Esempio n. 23
0
void TNodeGrid2D::writeToFile()
{
	
	checkInit();
	
	ofstream file("CSV/temp.csv", ios::out);
	
	FOR(j, NY)
	{
		FOR(i, NX)
			file << val[INDEX2D(i,j)] << ", ";
		file << "\n";
	}
void let_93(){
	Solution sol;
	vector<string>result=sol.restoreIpAddresses("172162541");
	FOR(i,result.size())cout<<result[i]<<endl;
	
	/*result=sol.restoreIpAddresses("25525511135");
	FOR(i,result.size())cout<<result[i]<<endl;
	
	result=sol.restoreIpAddresses("010010");
	FOR(i,result.size())cout<<result[i]<<endl;*/
	
	
}
Esempio n. 25
0
int main(void) {
    FILE *input = fopen("taxi.in", "r");
    FILE *output = fopen("taxi.out", "a");
    fscanf(input, "%lld%lld%d", &m, &d, &n);
    FOR(i, n) fscanf(input, "%lld", &dist[i]);

    long long joker = -1;
    int jokerPos = -1;
    FOR(i, n) if (dist[i] >= m - d && (joker == -1 || dist[i] < joker)) {
        joker = dist[i];
        jokerPos = i;
    }
    if (jokerPos == -1) {
        fprintf(output, "0");
        fclose(output);
        return 0;
    }

    if (jokerPos != n - 1) {
        dist[jokerPos] = dist[n - 1];
        dist[n - 1] = joker;
    }

    qsort(dist, n - 1, sizeof(dist[0]), cmp);


    long long int pos = 0;
    int use = 0;
    while (pos < d && use < n - 1) {
        if (dist[use] > d - pos) {
            pos += dist[use] - (d - pos);
            use++;
        } else
            break;
    }
    if (pos >= m) {
        // nothing
    } else if (pos >= d) {
        use++;
    } else {
        pos += joker - (d - pos);
        use++;
        if (pos < m) use = 0;
    }

    fprintf(output, "%d", use);

    fclose(input);
    fclose(output);
}
Esempio n. 26
0
int main(int argc, char **argv) {
    int n;
    scanf("%d", &n);

    FOR(i, MAX_LEVEL) gold[i] = silver[i] = stackCounts[i] = 0;

    FOR(i, n) {
        char line[MAX_LEVEL];
        scanf("%s", line);
        int l = strlen(line);
        stackCounts[l - 1]++;
        FOR(j, l)
            if (line[j] == 'S') silver[j]++; else gold[j]++;
    }
Esempio n. 27
0
int main(void) {
    int t = getInt();
    FOR(tt, t) {
        int n = getInt(), k = getInt();
        FOR(i, n) a[i] = getInt();

        long long int s = 0;
        FOR(i, n)
            if (s < 0) s = first[i] = a[i]; else first[i] = (s += a[i]);
        s = first[0];
        FOR(i, n) s = first[i] = max(s, first[i]);

        s = 0;
        for(int i=n-1;i>=0;i--)
            if (s < 0) s = last[i] = a[i]; else last[i] = (s += a[i]);
        s = last[n - 1];
        for(int i=n-1;i>=0;i--) s = last[i] = max(s, last[i]);

        s = first[0] + last[k + 1];
        FOR(i, n - k - 1) s = max(s, first[i] + last[i + k + 1]);

        printf("%lld\n", s);
    }
Esempio n. 28
0
void let_228(){
	ifstream fin;
	fin.open("let_228.txt");
	vector<int> nums;
	int value;
	while(!fin.eof()){
		fin>>value;
		nums.push_back(value);
	}

	Solution sol;
	vector<string> result=sol.summaryRanges(nums);
	FOR(i,result.size()) cout<<result[i]<<",";
	cout<<endl;
}
Esempio n. 29
0
int dijkstra(int s, int t) {
	int d[NN], u;
	bool in[NN];
	FOR(i, n) d[i] = p[s].d2(p[i]), in[i] = 0;
	while(!in[t]) {
		int best = 0x7fffffff;
		FOR(i, n) if(!in[i] && best > d[i]) best = d[u = i];
		in[u] = 1;
		FOR(i, n) if(!in[i]){
			int temp = p[u].d2(p[i]);
			d[i] = MIN(MAX(temp,d[u]),d[i]);
		}
	}
	return d[t];
}
void let_80(){
	ifstream fin;
	fin.open("let_80.txt");
	char tempc=' ';
	int value;
	vector<int> nums;
	while(fin.peek()!=']'){
		fin>>tempc>>value;
		nums.push_back(value);
	}
	Solution sol;
	cout<<sol.removeDuplicates(nums)<<endl;
	FOR(i,nums.size())cout<<nums[i]<<",";
	cout<<endl;
}