zoukankan      html  css  js  c++  java
  • 【CF1023E】Down or Right(交互,贪心)

    题意:

    n<=500

    思路:From https://blog.csdn.net/csdnjiangshan/article/details/81813227

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<string>
     4 #include<cmath>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<map>
     8 #include<set>
     9 #include<queue>
    10 #include<vector>
    11 #include<bitset>
    12 using namespace std;
    13 typedef long long ll;
    14 typedef unsigned int uint;
    15 typedef unsigned long long ull;
    16 typedef pair<int,int> PII;
    17 typedef vector<int> VI;
    18 #define fi first
    19 #define se second 
    20 #define MP make_pair
    21 #define N      210000
    22 #define M      51
    23 #define MOD 1000000007
    24 #define eps 1e-8 
    25 #define pi     acos(-1)
    26 #define oo     1e9
    27 
    28 char s[10];
    29 int ans[N];
    30 
    31 int query(int x1,int y1,int x2,int y2)
    32 {
    33     printf("? %d %d %d %d
    ",x1,y1,x2,y2);
    34     fflush(stdout);
    35     scanf("%s",s);
    36     if(s[0]=='Y') return 1;
    37     return 0;
    38 }
    39 
    40 int calc(int x1,int y1,int x2,int y2)
    41 {
    42     return abs(x1-x2)+abs(y1-y2);
    43 }
    44 
    45 int main()
    46 { 
    47     int n; 
    48     scanf("%d",&n);
    49     int x=1,y=1;
    50     int k=0;
    51     while(calc(x,y,n,n)>=n)
    52     {
    53         if(y+1<=n&&query(x,y+1,n,n))
    54         {
    55             y++; ans[++k]='R';
    56         }
    57          else
    58          {
    59              x++; ans[++k]='D';
    60          }
    61     }
    62     k=2*n-1; x=n; y=n;
    63     while(calc(x,y,1,1)>=n)
    64     {
    65         if(x-1>0&&query(1,1,x-1,y))
    66         {
    67             x--; ans[--k]='D';
    68         }
    69          else
    70          {
    71              y--; ans[--k]='R';
    72          }
    73     }    
    74     printf("! ");
    75     for(int i=1;i<=2*n-2;i++) printf("%c",ans[i]);
    76     return 0;
    77 }
  • 相关阅读:
    UNIT THREE
    UNIT TWO
    UNIT ONE
    实验九 根据材料编程
    实验五 编写、调试具有多个段的程序
    实验 四 [bx]和loop的使用
    实验二 用机器指令和汇编指令编程
    实验三 编程、编译、连接、跟踪
    实验一 查看CPU和内存,用机器指令和汇编指令编程
    汇编语言第5~8章知识总结
  • 原文地址:https://www.cnblogs.com/myx12345/p/10077993.html
Copyright © 2011-2022 走看看