inline void XmlNode::appendTail(std::ostream& ss) const { if (!alone()) { ss << "</" << name << ">"; } }
int main() { int t, i, n, arr[500]; scanf("%d", &t); while (t--) { scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &arr[i]); alone(arr, n); } return 0; }
int solve_sudoku(sudoku_board board, int side){ int i=0; while (1){ //printf("\tALONE\n"); if (alone(board, side)) continue; if (check_solution(board, side)==0) break; //printf("\t\tSINGLETON\n"); if (singleton(board, side, 0, 0, side, side)) continue; if (check_solution(board, side)==0) break; //printf("\t\t\tPAIRS\n"); if (pairs(board, side, 0, 0, side, side)) continue; if (check_solution(board, side)==0) break; //print_board(board, side); //printf("\t\t\t\tBAD POSSIBLE\n"); i=bad_possible_elimination(board, side); //printf(" %d\n", i); if(i) continue; if (check_solution(board, side)==0) break; //printf("\t\t\t\t\tRECURSIVE\n"); recursive_solution(board, side, 0, 0); break; } /*switch (check_solution(board, side)) { case 0: printf("\n--OK--\n"); break; case 1: printf("\n--ERRORS--\n"); break; case 2: printf("\n--MISSES--\n"); break; default: break; }*/ return 0; }
void place_me(t_env *env) { srand(time(NULL)); env->mem_share = (t_share*)shmat(env->segment_id, NULL, 0); if (alone(env, env->team) == 0) env->mem_share->nb_team++; env->mem_share->nb_player++; env->x = rand() % WIDTH; env->y = rand() % HEIGTH; while (env->mem_share->game[env->y][env->x] != -1) { env->x = rand() % WIDTH; env->y = rand() % HEIGTH; } env->mem_share->game[env->y][env->x] = env->team; shmdt(env->mem_share); }
void update() { // move around if (!stuck) { // get random int [-1, 1] (hence 2) x += ci::Rand::randInt(-1, 2); y += ci::Rand::randInt(-1, 2); if (x < 0 || y < 0 || x >= width || y >= height) { reset(); return; } // test if something is next to us if (!alone()) { stuck = true; field[y * width + x] = true; } } }
void AggParticle::update(){ if(!stuck){ // random walk x += round(ofRandom(-1, 1)); y += round(ofRandom(-1, 1)); // check border if(x < 0) x = w; if(y < 0) y = h; if(x > w) x = 0; if(y > h) y = 0; // check alone if(!alone()){ stuck = true; field[y * w + x] = true; } } }
int main(int argc, char **argv) { int *a, i, j, n, m; char **t; if (argc != 3) return EXIT_FAILURE; n = atoi(argv[1]); m = atoi(argv[2]); if (n <= 0 || m > n*n || m < 0) return EXIT_FAILURE; srand((unsigned int)time(NULL)); a = malloc(n*n*sizeof(int)); t = malloc(n*sizeof(char*)); for (i = 0 ; i != n ; ++i) { t[i] = malloc(n*sizeof(char)); for (j = 0 ; j != n ; ++j) t[i][j] = ' '; } for (i = 0 ; i != n*n ; ++i) a[i] = i; printf("%d\n", n); for (i = 0 ; i != m ; ++i) { swap(a, i, rand()%(n*n-i)+i); t[a[i]/n][a[i]%n] = '#'; printf("%d %d\n", a[i]/n+1, a[i]%n+1); } for (i = 0 ; i != n ; ++i) for (j = 0 ; j != n ; ++j) if (alone(t, n, i, j)) printf("%d %d\n", i+1, j+1); for (i = 0 ; i != n ; ++i) free(t[i]); free(t); free(a); return EXIT_SUCCESS; }
inline std::string XmlNode::closeTag() const { return alone() ? "/" : ""; }
int bad_possible_elimination(sudoku_board board, int side){ int i, j, k, n, m,aa=0, abc, alone_ok=0; sudoku_board test_board; // print_board(board, side); for (i=0; i<side; ++i) {//ROW for (j=0; j<side; ++j) {//COLUMN //printf("row=%d column=%d\n", i, j); //printf("\tvalue = %d\n", get_value(&board[i][j])); if (get_value(&board[i][j])==0) { for (k=0; k<side; ++k) {//POSSIBLE //printf("k=%d possible=%d\n", k, board[i][j].possible[k]); if (board[i][j].possible[k]){ test_board = create_board(side); for (n=0; n<side; ++n) for (m=0; m<side; ++m){ if (get_value(&board[n][m])) found_value(test_board, side, n, m, get_value(&board[n][m])); } found_value(test_board, side, i, j, board[i][j].possible[k]); alone_ok=0; for (n=0; n<side; ++n) { if ((board[i][n].possibles)==1) { for (m=0; m<side; ++m) { if (board[i][n].possible[m]) { alone_ok = 1; found_value(test_board, side, i, n, board[i][n].possible[m]); } } } if ((board[n][j].possibles)==1) { for (m=0; m<side; ++m) { if (board[n][j].possible[m]) { alone_ok = 1; found_value(test_board, side, n, j, board[n][j].possible[m]); } } } } if (singleton(test_board, side, i, j, i+1, j+1)) alone_ok = 1; if (pairs(test_board, side, i, j, i+1, j+1)) alone_ok = 1; if (alone_ok) { while (1){ if (alone(board, side)) continue; if (singleton(board, side, 0, 0, side, side)) continue; if (pairs(board, side, 0, 0, side, side)) continue; break; } } abc = check_solution(test_board, side); //printf("%d\n", aa); switch (abc) { case 0: found_value(board, side, i, j, board[i][j].possible[k]); delete_board(test_board, side); return -1; case 1: delete_possible(&board[i][j], board[i][j].possible[k], side); ++aa; break; default: break; } delete_board(test_board, side); } } } } } return aa; }
static Atomic read_a(char *s, int *len) { if(s[0]=='(') { *len=1; return A_RBRA; } if(s[0]==')') { *len=1; return A_RCET; } if(s[0]=='{') { *len=1; return A_FBRA; } if(s[0]=='}') { *len=1; return A_FCET; } if(s[0]=='[') { *len=1; return A_QBRA; } if(s[0]==']') { *len=1; return A_QCET; } if(s[0]=='.') { *len=1; return A_POINT; } if(s[0]==';') { *len=1; return A_SECO; } if(s[0]==',') { *len=1; return A_COMMA; } if(s[0]=='\'') return read_quoted(s,len,'\''); if(s[0]=='\"') return read_quoted(s,len,'\"'); if(s[0]=='`') { *len=1; return A_RQUOTE; } if(isalpha(s[0]) || s[0]=='_' || s[0]=='~') { int alen; alen=0; while(isalnum(s[alen]) || s[alen]=='_' || s[alen]=='~' ) alen++; *len=alen; return NewAtom(s,alen); } /* test for numbers */ if(isdigit(s[0]) /*|| (s[0]=='-' && isdigit(s[1]))*/ ) { int negflag=0; int alen=0; int lll; if(s[0]=='-') {negflag=1; s++; alen++; } lll=0; while(isdigit(s[lll])) lll++; if((s[lll]=='e' || s[lll]=='E') && (isdigit(s[lll+1]) || s[lll+1]=='-')) { double f=0.0; int eneg=0,exp=0; while(s[0]!='e' && s[0]!='E') { f*=10.0; f+=s[0]-'0'; s++; alen++; } if(negflag) f=-f; s++; alen++; if(s[0]=='-') { s++; alen++; eneg=1; } if(s[0]=='+') { s++; alen++; } while(isdigit(s[0])) { exp*=10; exp+=s[0]-'0'; s++; alen++; } if(eneg) exp=-exp; f*=pow(10.0,exp); *len=alen; return NewFloat(f); } if(s[lll]=='.' && isdigit(s[lll+1])) { double f=0.0; double fact=1.0; while(s[0]!='.') { f*=10.0; f+=s[0]-'0'; s++; alen++; } s++; alen++; while(isdigit(s[0])) { fact/=10.0; f+=fact*(s[0]-'0'); s++; alen++; } if(negflag) f=-f; if(s[0]=='e' || s[0]=='E') { int eneg=0; int exp=0; s++; alen++; if(s[0]=='-') { s++; alen++; eneg=1; } if(s[0]=='+') { s++; alen++; } while(isdigit(s[0])) { exp*=10; exp+=s[0]-'0'; s++; alen++; } if(eneg) exp=-exp; f*=pow(10.0,exp); } *len=alen; return NewFloat(f); } lll=0; while(isdigit(s[0])) { lll*=10; lll+=s[0]-'0'; s++; alen++; } if(negflag) lll=-lll; *len=alen; return NewInteger(lll); } if(ispunct(s[0])) { int alen; alen=0; while(ispunct(s[alen]) && !alone(s[alen]) && !(alen>0 && s[alen-1] == '=' && s[alen]!= '=') ) alen++; *len=alen; return NewAtom(s,alen); } *len=1; return NewAtom("???",0); }