Lugou P1092 Insect Food Calculation

Source: Internet
Author: User

Portal

Thinking of solving problems

Just started according to Yzy God Ben to the method of writing, is every time to calculate the calculated out, the result because too much food write hung. After the direct explosion of water.

#include <iostream>#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>using namespacestd;Const intmaxn= +;intn,a[maxn],cnt;Chars[4][MAXN];BOOLVis[maxn],flag;BOOLCheck () { for(Registerintj=n;j;j--){        if(a[s[1][j]-'A']<0|| a[s[3][j]-'A']<0|| a[s[2][j]-'A']<0)Continue; if((a[s[1][j]-'A']+a[s[2][j]-'A'])%n!=a[s[3][j]-'A']         && (a[s[1][j]-'A']+a[s[2][j]-'A']+1)%n!=a[s[3][j]-'A'])return false; }    return true;}BOOLPD () {intPre=0;  for(Registerintj=n;j;j--){        if((a[s[1][j]-'A']+a[s[2][j]-'A']+pre)%n!=a[s[3][j]-'A'])return false; Pre= (a[s[1][j]-'A']+a[s[2][j]-'A']+PRE)/N; }    returnPre?false:true;}voidDfsintXintNow ) {    if(now==4) {now=1; x--;if(x==0) {if(PD ()) flag=1;return;}} if(a[s[now][x]-'A']>=0) {DFS (x,now+1);return;}  for(Registerinti=n-1; i>=0; i--){        if(Vis[i])Continue; Vis[i]=1; a[s[now][x]-'A']=i; if(!check ()) {vis[i]=0; a[s[now][x]-'A']=-1;Continue;} DFS (X,now+1);if(flag)return; vis[i]=0; a[s[now][x]-'A']=-1; }}intMain () {memset (A,-1,sizeof(a)); scanf ("%d%s%s%s", &n,s[1]+1, s[2]+1, s[3]+1); DFS (N,1);  for(RegisterintI=0; i<n;i++) printf ("%d", A[i]); return 0;}/*4BADCCBDADCCC*/
View Code

Lugou P1092 Insect Food Calculation

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.