Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

话说这题有没有什么犀利的数据啊

Posted by zheng_bo at 2013-09-17 21:09:18 on Problem 1348
= = 和别人的AC代码拍了几百组都是对的,但就是不给过。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;
const int INF = 99999999;
const int MAXN = 100005;
const double EPS = 1.0e-12;

int a[6];
bool flag,vis[10];

double f(double a,double b,int op)
{
      switch(op)
      {
            case 1 :
                  return a + b;
                  break;
            case 2 :
                  return a - b;
                  break;
            case 3 :
                  return a * b;
                  break;
            case 4 :
                  return a / b;
                  break;
            default :
                  break;
      }
}

void dfs(double res,int cnt,int op)
{
      if (cnt == 7)
      {
            if (fabs(res-a[5]) <= EPS)flag = 1;
            return ;
      }
      if (!flag)
      {
            if (cnt % 2)
            {
                  for (int i = 1;i <= 4 && !flag;i++)
                  {
                        dfs(res,cnt+1,i);
                  }
            }
            else
            {
                  for (int i = 1;i <= 4 && !flag;i++)if (vis[i] == 0)
                  {
                        if (op == 4 && a[i] == 0)continue;
                        double temp = f(res,(double)a[i],op);
                        vis[i] = 1;
                        dfs(temp,cnt+1,op);
                        vis[i] = 0;
                  }
                  for (int i = 1;i <= 4 && !flag;i++)if (vis[i] == 0)
                  {
                        if (op == 4 && fabs(res) <= EPS)continue;
                        double temp = f((double)a[i],res,op);
                        vis[i] = 1;
                        dfs(temp,cnt+1,op);
                        vis[i] = 0;
                  }
            }
      }
}

bool isok()
{
      memset(vis,0,sizeof(vis));
      flag = 0;
      for (int i = 1;i <= 4 && !flag;i++)
      {
            vis[i] = 1;
            dfs(a[i]*1.0,1,0);
            vis[i] = 0;
      }
      return flag;
}

int main()
{
      int cas = 1;
      while (scanf("%d",&a[1]) && a[1] != -1)
      {
            for (int i = 2;i <= 5;i++)scanf("%d",&a[i]);
            for (int i = 1;i <= 5;i++)printf("%d ",a[i]);
            if (isok())printf("OK!\n");
            else printf("NO!\n");
      }
      return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator