2018.10.15 Practice Race Search for a special practice

Source: Internet
Author: User
Tags fread

Solving the T1 by integral solution: preprocessing\ (n\)The approximate, with\ (f[i][j]\)The record is based on the first factor of the sort, continuous\ (j\)The product of a factor. Requirements\ (ffi][j]<=n\)And\ (j<=k\)\ (code\):
#include <cstdio> #include <algorithm> #include <iostream> #include <ctype.h> #include <    Ctime> #define LL Long longusing namespace Std;char buf[1<<20],*p1,*p2;inline char gc () {//return GetChar (); Return p1==p2&& (p2= (p1=buf) +fread (Buf,1,1<<20,stdin)) ==p1?0:*p1++;}    Template<typename t>inline void Read (T &x) {char tt;    while (!isdigit (TT=GC ())); x=tt-' 0 '; while (IsDigit (TT=GC ())) x=x*10+tt-' 0 ';}     ll T,n,m,tot;ll s[100005],fac[100005][30];d ouble start;bool dfs (ll x,ll rest,ll fact) {if (!rest) return fact==n;rest--;        while (x) {if (X+rest>tot) return 0; if (fac[x][rest]>n| |        Fac[x][rest]*fact>n) return 0;    if (Dfs (X+1,REST,FACT*S[X))) return 1;x++;    }}int Main () {read (t);        while (t--) {bool flag=0;        ll Fact=1;        Read (n), read (m);        if (n==1&&m==2) {puts ("NIE"); continue;}            if (m<=2) {puts ("TAK");        Continue } for (int i=1;i<=m;i++,fact*=i) if (fact>n) {flag=1;        Break        } if (flag) {puts ("NIE"); continue;}        int i;tot=0;        for (i=1;i*i<n;i++) if (n%i==0) s[++tot]=i,s[++tot]=n/i;        if (i*i==n) s[++tot]=i;        Sort (s+1,s+tot+1); fact=1; for (int i=1;i<=tot;i++,fact=1) for (int j=0;j<m&&i+j<=tot;j++) {if (fact<=n) F            ACT*=S[I+J];        Fac[i][j]=fact;        }//for (int i=1;i<=10;i++)//printf ("%d", f[3][i]);        if (Dfs (1,m,1)) printf ("tak\n");    else printf ("nie\n"); }}//1 1000000000 6
T2 Minesweeper Puzzle: Preprocessing\ (i\),\ (j\)Two points through the line, the search can be\ (code:\)
#include <stdio.h> #include <cstring> #include <algorithm> #define LOWBIT (x) x&-xusing namespace    std;struct node{int x, y; inline node (int a=0,int b=0) {x=a,y=b;}}    A[20];int n,k;int f[1<<17],line[20][20];int dfs (int s) {if (~f[s]) return f[s];    int cnt=0,t=s;    while (t) cnt++,t^=lowbit (t);    if (n-k>=cnt) return f[s]=0;    if (cnt==1) return f[s]=1;    f[s]=1e9+9; for (int i=0;i<n;i++) if (s>>i&1) for (int j=i+1;j<n;j++) if (s>>j&1) f[s]=min (F[s],dfs (s& (~line[i][j]))    +1); return f[s];}        int main () {for (int t=1;t<=2;t++) {memset (f,-1,sizeof (f));        memset (line,0,sizeof (line));        scanf ("%d%d", &n,&k);            for (int i=0;i<n;i++) {int x, y;            scanf ("%d%d", &x,&y);        A[i]=node (x, y); }//(Ay-ky) (AX-BX) = = (Ax-kx) (ay-by) for (int. i=0;i<n;i++) for (int j=0;j<n;j++) if (i!=j) fo R (int k=0;k<n;k++) if ((A[I].Y-A[K].Y) * (a[i].x-a[j].x) = = (a[i].x-a[k].x) * (A[I].Y-A[J].Y)) line[i][j]|= (1<<k);    printf ("%d\n", Dfs ((1<<n)-1)); }}
T3 Digital Elimination Game puzzle: a*+ iterative deepening + expansion around the color + unreal assignment, Mark connectivity\ (code:\)
#include <cstdio> #include <algorithm> #include <iostream> #include <cmath> #include < stdlib.h> #include <ctype.h> #define EPS 1e-7#define ll long longusing namespace Std;char buf[1<<20],*p1,*    P2;inline Char GC () {return GetChar (); Return p1==p2&& (p2= (p1=buf) +fread (Buf,1,1<<20,stdin)) ==p1?0:*p1++;}    Template<typename t>inline void Read (T &x) {char tt;    while (!isdigit (TT=GC ())); x=tt-' 0 '; while (IsDigit (TT=GC ())) x=x*10+tt-' 0 ';}    int n;int a[10][10],book[10][10];int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};bool cl[10];int Gujia () {int col=0;    for (int i=0;i<=5;i++) cl[i]=0;         for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (!cl[a[i][j]]&&book[i][j]!=1) {cl[a[i][j]]=1;    col++; } return col;}    void Dfs (int x,int y,int c) {book[x][y]=1;        for (int i=0;i<4;i++) {int tx=x+dx[i],ty=y+dy[i]; if (tx<=0| | ty<=0| | tx>n| |        Ty>n) continue; if (book[tx][ty]==1) CONtinue;        book[tx][ty]=2;    if (a[tx][ty]==c) DFS (TX,TY,C);    }}int Fill (int c) {int sum=0;        for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (a[i][j]==c&&book[i][j]==2) {sum++;    DFS (I,J,C); } return sum;}    BOOL Astar (int dep,int maxdep) {int G=gujia ();    if (DEP+G&GT;MAXDEP) return 0;    if (!g) return 1;    int temp[10][10]; for (int i=0;i<=5;i++) {for (Int. c=1;c<=n;c++) for (int j=1;j<=n;j++) TEMP[C][J]=BOOK[C][J]                ;                if (Fill (i) &&astar (DEP+1,MAXDEP)) return 1;    for (int. c=1;c<=n;c++) for (int j=1;j<=n;j++) BOOK[C][J]=TEMP[C][J]; } return 0;}        int main () {while (1) {read (n);        if (!n) return 0;                for (int. i=1;i<=n;i++) for (int j=1;j<=n;j++) read (a[i][j]);                for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) book[i][j]=0;        DFS (1,1,a[1][1]); for (int Dep=0;;            dep++) if (Astar (0,DEP)) {printf ("%d\n", DEP);        Break }    }}

2018.10.15 Practice Race Search for a special practice

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.