zoukankan      html  css  js  c++  java
  • codeforces Round#379 div.2

    第一次打Codeforces,纪念一下

    前两题水题不表

    第三题:二分

    因为有序二分查出符合要求最大的第二种魔法,再遍历第一种魔法

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<map>
     6 #include<vector>
     7 using namespace std;
     8 const int maxn=2e5+20;
    10 #define LL long long
    11 LL a[maxn],b[maxn],c[maxn],d[maxn];
    12 int main()
    13 {
    14     LL n,m,k,x,s;
    15     while(scanf("%lld%lld%lld",&n,&m,&k)!=EOF)
    16     {
    17         scanf("%lld%lld",&x,&s);
    18         for(int i=0;i<m;++i)
    19             scanf("%lld",&a[i]);
    20         for(int i=0;i<m;++i)
    21             scanf("%lld",&b[i]);
    22         for(int i=1;i<=k;++i)
    23             scanf("%lld",&c[i]);
    24         for(int i=1;i<=k;++i)
    25             scanf("%lld",&d[i]);
    26         LL ans=(n-c[upper_bound(d+1,d+k+1,s)-d-1])*x;//数组下标从1开始,避免数组下标可能为-1,不够用返回c[0]
    27         for(int i=0;i<m;i++)
    28         {
    29             if(b[i]>s)
    30                 continue;
    31           ans = min(ans, (n - c[upper_bound(d+1,d+k+1,s-b[i])-d-1]) * a[i]);
    32         }
    33         printf("%lld
    ",ans);
    34     }
    35     return 0;
    36 }

    第四题: 734D Anton and Chess 几何+模拟

    一开始理解错题意以为是一边下棋一边check,其实不是最后check

    最后In Check的棋子来自king 8个方向中的最近的棋子 保留该棋子 最后在判断下即可

    注意判断来自横向纵向对角线方向的最近棋子距离——切比雪夫距离

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<map>
     6 #include<vector>
     7 using namespace std;
     8 typedef long long ll;
     9 const int N=5e5+20;
    10 struct point
    11 {
    12     char kind;
    13     int x,y;
    14 }near[8];//因为不能Leap,保留king8个方向中最近的棋子即可
    15 int x0,y0;
    16 
    17 int Dir(point cur)
    18 {
    19     if(cur.x==x0&&cur.y<y0)return 0;//hor 上下
    20     if(cur.x==x0&&cur.y>y0) return 1;//
    21 
    22     if(cur.y==y0&&cur.x<x0) return 2;//ver 左右方
    23     if(cur.y==y0&&cur.x>x0) return 3;//
    24 
    25     if(x0+y0==cur.x+cur.y&&cur.y<y0) return 4;//主对角线下方
    26     if(x0+y0==cur.x+cur.y&&cur.y>y0) return 5;//主对角线上方
    27 
    28     if(x0-y0==cur.x-cur.y&&cur.y<y0) return 6;//副对角线上
    29     if(x0-y0==cur.x-cur.y&&cur.y>y0) return 7; //副下
    30 
    31     return -1;//不在8个方向上
    32 }
    33 int dist(int a,int b)//切比雪夫距离
    34 {
    35     return max(abs(x0-a),abs(y0-b));
    36 }
    37 void update(point& old,point cur)
    38 {
    39     if(old.kind=='?'||dist(cur.x,cur.y)<dist(old.x,old.y))
    40     {
    41         old=cur;
    42     }
    43 }
    44 
    45 int main()
    46 {
    47     int n;
    48     cin>>n;
    49     cin>>x0>>y0;
    50     for(int i=0;i<8;i++)
    51     {
    52         near[i].kind='?';
    53     }
    54     for(int i=0;i<n;i++)
    55     {
    56         point cur;
    57         cin>>cur.kind>>cur.x>>cur.y;
    58         int dir=Dir(cur);//判断该点是否在king的8个方向上
    59         if(dir>=0)
    60         {
    61             update(near[dir],cur);//更新该方向上的最近点
    62         }
    63     }
    64     bool flag=false;
    65     for(int i=0;i<8;i++)
    66     {
    67         if(i<4&&(near[i].kind=='R'||near[i].kind=='Q'))
    68         {
    69             flag=true;
    70             break;
    71         }
    72         if(i>=4&&(near[i].kind=='B'||near[i].kind=='Q'))
    73         {
    74             flag=true;
    75             break;
    76         }
    77     }
    78     if(flag)
    79     cout<<"YES"<<endl;
    80     else
    81     cout<<"NO"<<endl;
    82     return 0;
    83 }
  • 相关阅读:
    【WF2017】Mission Improbable
    【Codeforces 837D】Round Subset
    【Codeforces 788C】The Great Mixing
    【JSOI2008】最大数
    2.1图像的数字化
    MATLAB生成随机数
    四六级准考证号忘记了如何快速查询四六级成绩?
    加密与水印结合
    如何在 PyPI安装python的软件包?
    matlab中如何定义函数
  • 原文地址:https://www.cnblogs.com/demian/p/6070209.html
Copyright © 2011-2022 走看看