zoukankan      html  css  js  c++  java
  • CodeForces Goodbye 2017

    传送门

    A - New Year and Counting Cards

    •题意

    有n张牌,正面有字母,反面有数字

    其中元音字母$a,e,o,i,u$的另一面必须对应$0,2,4,6,8$的偶数

    其他字母可以和任意数字对应

    问至少检查几次可以使这n张牌合法

    •思路

    由于偶数可以对应任何牌,但奇数必须对应不是元音的字母,所以所有的奇数要检查

    由于元音字母只可以对应偶数,其他字母可以对应任意的数,所以元音字母要检查

    记录元音字母+奇数的个数

    •代码

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 string s;
     4 int main()
     5 {
     6     cin>>s;
     7     int num=0;
     8     for(int i=0;i<s.length();i++)
     9     {
    10         int a=s[i]-'0';
    11         if(((a&1)&&a>0&&a<10)||s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')
    12             num++;
    13     }
    14     printf("%d
    ",num);
    15 }
    View Code

    B.New Year and Buggy Bot

    •题意

    给一个迷宫,其中$S$代表起点,$E$代表终点,$#$代表障碍物,#.#代表道路

    $0,1,2,3$代表上下左右四个方位(顺序不一定),

    给定一个序列,问按照序列走,从起点到终点一共多少种走法

    •思路

    对$0,1,2,3$进行全排列,第1,,2,3,4个位置分别代表上下左右

    记录从起点到终点的方案数

    •代码

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 char s[55][55];
     4 char t[105];
     5 int a[4]={0,1,2,3};
     6 int num=0;
     7 int n,m;
     8 struct node
     9 {
    10     int x,y;
    11 }st,en;
    12 void solve(int u,int d,int l,int r)
    13 {
    14     int len=strlen(t+1);
    15     int x=st.x,y=st.y;
    16     for(int i=1;i<=len;i++)
    17     {
    18         int now=t[i]-'0';
    19         if(now==u)
    20             x--;
    21         else if(now==d)
    22             x++;
    23         else if(now==l)
    24             y--;
    25         else if(now==r)
    26             y++;
    27 
    28         if(s[x][y]=='#'||x<1||x>n||y<1||y>m)
    29             return ;
    30         if(x==en.x&&y==en.y)
    31         {
    32             num++;
    33             return ;
    34         }
    35     }
    36 }
    37 int main()
    38 {
    39     scanf("%d%d",&n,&m);
    40     for(int i=1;i<=n;i++)
    41         scanf("%s",s[i]+1);
    42     for(int i=1;i<=n;i++)
    43     {
    44         for(int j=1;j<=m;j++)
    45         {
    46             if(s[i][j]=='S')
    47                 st={i,j};
    48             if(s[i][j]=='E')
    49                 en={i,j};
    50         }
    51     }
    52     scanf("%s",t+1);
    53     do
    54     {
    55         solve(a[0],a[1],a[2],a[3]);
    56     }while(next_permutation(a,a+4));
    57 
    58     printf("%d
    ",num);
    59 }
    View Code

    C - New Year and Curling

    •题意

    有n个实心圆在无穷远处,给出他们圆心的横坐标

    现从无穷远处按照从1到n的顺序,往x轴推圆

    由于圆是实心的,所以不能相交

    问推完后每个圆的圆心的y坐标

    •思路

    一个圆不能再推动的前提是

    ①推到了x轴

    ②与其他圆相切

     与其他圆相切的时候,只要一相切就不会再动了,也就是不能绕过相切早的去和晚的相切

    可以假设可以都可以推到x轴,然后挨个去找前面可以和他相切的

    注意找的是y坐标最大的,也就是相切最早的那一个

    y坐标可以这么计算出 $h=(2r)^{2}-d^2$ (其中$d=a[i]-a[j]$) ,于是$b[j]=b[i]+h$

    •代码

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int n,r;
     4 int L,R;
     5 int a[1005];
     6 double b[1005];
     7 int main()
     8 {
     9     scanf("%d%d",&n,&r);
    10     for(int i=1;i<=n;i++)
    11         scanf("%d",a+i);
    12     for(int i=1;i<=n;i++)
    13     {
    14         b[i]=1.0*r;
    15         for(int j=1;j<i;j++)
    16         {
    17             int d=a[i]-a[j];
    18             b[i]=max(b[i],b[j]+sqrt(4*r*r-d*d));
    19         }
    20     }
    21     for(int i=1;i<=n;i++)
    22         printf("%.10f ",b[i]);
    23 }
    View Code
  • 相关阅读:
    UOJ #455 [UER #8]雪灾与外卖 (贪心、模拟费用流)
    Codeforces 482E ELCA (LCT)
    Codeforces 798D Mike and distribution (构造)
    AtCoder AGC017C Snuke and Spells
    HDU 6089 Rikka with Terrorist (线段树)
    HDU 6136 Death Podracing (堆)
    AtCoder AGC032D Rotation Sort (DP)
    jenkins+python+kubectl实现批量更新k8s镜像
    Linux 下载最新kubectl版本的命令:
    jenkins X 和k8s CI/CD
  • 原文地址:https://www.cnblogs.com/MMMinoz/p/11616206.html
Copyright © 2011-2022 走看看