zoukankan      html  css  js  c++  java
  • 2020年3月28日UCF Local Programming Contest 2016

    A. Majestic 10

    题意:给你三个数,要你判断三个数中有多少个数是大于等于10的,并根据数量打印相关输出即可

    题解:这是一道简单的签到题,简单。

    代码:

     1 #include<iostream>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define ll long long
     5 using namespace std;
     6 int main(){
     7     ll n;
     8     cin>>n;
     9     while(n--){
    10         int num=0,t;
    11         int cnt[3]={0},tt=0; 
    12         for(int i=0;i<3;i++){  
    13             cin>>t;
    14             cnt[tt++]=t;
    15             if(t>=10){
    16                 num++;
    17             }
    18         }
    19         for(int i=0;i<tt;i++){
    20             cout<<cnt[i];
    21             if(i<tt-1){
    22                 cout<<" ";
    23             }else{
    24                 cout<<endl;
    25             }
    26         }
    27         if(num==0){
    28             cout<<"zilch"<<endl;
    29         }else if(num==1){
    30             cout<<"double"<<endl;
    31         }else if(num==2){
    32             cout<<"double-double"<<endl;
    33         }else{
    34             cout<<"triple-double"<<endl;
    35         }
    36         cout<<endl;
    37     }
    38     return 0;
    39 } 
    View Code

    B. Phoneme Palindromes

    题意:大概意思就是要你判断题目给出的两个字符串是不是回文串,但又有点创新,就是给出了即使两个字不同也可将其视为是相同的,这个下面的输入会给出那两个字母符合这一特性

    题解:根据常规的回文串判断方法来判断即可,在遇到如果不是回文串的时候,可将两个字符串中的有“歧义”的字母都进行替换再进行比较即可。

    代码:

     1 #include<iostream>
     2 #include<cstring>
     3 #include<map>
     4 #include<algorithm>
     5 using namespace std;
     6 #define ll long long
     7 int main(){    
     8     ll n,p,q;
     9     string ptr1;
    10     char c1,c2;
    11     cin>>n;
    12     int num=1;
    13     while(n--){
    14         cin>>p;
    15         map<char,char> mp;
    16         for(int i=0;i<p;i++){
    17             cin>>c1>>c2;
    18             mp[c1]=c2;
    19         }
    20         cin>>q;
    21         cout<<"Test case #"<<num<<":"<<endl;
    22         num++;
    23         for(int i=0;i<q;i++){//这是判断的 
    24             cin>>ptr1;
    25             string pr=ptr1;//原始 
    26             string ptr2(ptr1.rbegin(),ptr1.rend());
    27             if(ptr1==ptr2){
    28                 cout<<pr<<" "<<"YES"<<endl;
    29             }else{
    30                 for(int j=0;j<ptr2.length();j++){
    31                     if(mp.count(ptr2[j])!=0){//表示存在 
    32                         ptr2[j]=mp[ptr2[j]];
    33                     }
    34                 }
    35                 for(int j=0;j<ptr1.length();j++){
    36                     if(mp.count(ptr1[j])!=0){
    37                         ptr1[j]=mp[ptr1[j]];
    38                     }
    39                 }
    40                 if(ptr1==ptr2){
    41                     cout<<pr<<" "<<"YES"<<endl;
    42                 }else{
    43                     cout<<pr<<" "<<"NO"<<endl;
    44                 }
    45             }
    46         }
    47         cout<<endl;
    48     }
    49     return 0;
    50 }
    View Code

    C. Don't Break the Ice

    题意:大概意思就是给你一个充满冰块的棋盘,你可以对其中任何一个冰块进行敲击,冰块回随之掉落,但它的掉落会是一个连锁反应,他旁边的冰块也会掉落,除非旁边的冰块是在一个完整的行或列中,而掉落的这个冰块同样也会以同样的机理影响其他的冰块,想要你求下面给出的操作步骤有几个是多余的。

    题解:这一题的意思比较简单,简单暴力模拟整个过程即可,但这个过程比较复杂,细心即可。

    代码:

     1 #include<iostream>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 #define ll long long
     6 ll D,N,x,y; 
     7 ll num[100][100]={0};
     8 int net[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
     9 bool check(int dx,int dy){
    10     return (dx>=1&&dy<=D)&&(dy>=1&&dy<=D);    
    11 } 
    12 int main(){
    13     ll n;//样例的数量
    14     cin>>n;
    15     int g=1;
    16     while(n--){
    17         cin>>D>>N;
    18         for(int i=1;i<=D;i++){
    19             for(int j=1;j<=D;j++){
    20                 num[i][j]=1;
    21             }
    22         }//初始化为  1  表示这个位置还有冰块 
    23         ll sum=0;//存储答案 
    24         for(int i=0;i<N;i++){//输入每一次的操作 
    25             cin>>x>>y;
    26             if(num[x][y]==0){//本次操作无效 
    27                 sum++;
    28             }else{//本次操作是有效的 
    29                 num[x][y]=0;//表示这一个冰块回掉下去 ,是以它为中心开始掉落的 
    30                 //但是它会影响它周围的冰块
    31                 for(int j=0;j<4;j++){
    32                     int dx=x+net[j][0];
    33                     int dy=y+net[j][1];
    34                     if(check(dx,dy)&&num[dx][dy]==1){
    35                         if(j==0){//向右移动 
    36                             for(int r=dy;r<=D;r++){
    37                                 int ff=0;
    38                                 for(int rr=1;rr<=D;rr++){
    39                                     if(num[rr][r]==1){
    40                                         ff++;
    41                                     }
    42                                 }
    43                                 if(ff==D){}
    44                                 else {//不完整 
    45                                     num[dx][r]=0;
    46                                 }
    47                             }
    48                         }else if(j==1){//向左移动 
    49                             for(int r=dy;r>=1;r--){
    50                                 int ff=0;
    51                                 for(int rr=1;rr<=D;rr++){
    52                                     if(num[rr][r]==1){
    53                                         ff++;
    54                                     }
    55                                 }
    56                                 if(ff==D){}
    57                                 else{//不完整 
    58                                     num[dx][r]=0;
    59                                 }
    60                             }
    61                         }else if(j==2){//向上移动 
    62                             for(int r=dx;r<=D;r++){
    63                                 int ff=0;
    64                                 for(int rr=1;rr<=D;rr++){
    65                                     if(num[r][rr]==1){
    66                                         ff++;
    67                                     }
    68                                 }
    69                                 if(ff==D){}
    70                                 else{
    71                                     num[r][dy]=0;
    72                                 }
    73                             }
    74                         }else if(j==3){//向下移动 
    75                             for(int r=dx;r>=1;r--){
    76                                 int ff=0;
    77                                 for(int rr=1;rr<=D;rr++){
    78                                     if(num[r][rr]==1){
    79                                         ff++;
    80                                     }
    81                                 }
    82                                 if(ff==D){}
    83                                 else{//不完整 
    84                                     num[r][dy]=0;
    85                                 }
    86                             }
    87                         }
    88                     }
    89                 }
    90             }
    91         }
    92         cout<<"Strategy #"<<g<<": "<<sum<<endl;
    93         g++;
    94         cout<<endl;
    95     } 
    96     return 0;
    97 }
    View Code

    E. Loopy Word Search

    题意:题意比较简单,就是要你寻找一个字符串在题目所给的字母“矩阵”中第一个字母出现的位置和方向

    题解:这一题也可一简单暴力模拟这个过程,唯一的技巧就是可以对题目给出的字母“矩阵”进行翻转以达到扩大字符串长度的目的,当让扩充的长度是多少要根据题目的具体要求来,这里我将它扩大到长度为10000的字符串

    代码:

      1 #include<iostream>
      2 #include<cstring>
      3 #include<algorithm>
      4 using namespace std;
      5 #define ll long long
      6 int main(){
      7     ll n;
      8     cin>>n;
      9     ll r,c; 
     10     string arr;
     11     ll num;
     12     int g=1;
     13     while(n--){//字谜的个数 
     14         scanf("%d %d",&r,&c);//行和列
     15         char ptr[100][100];
     16         for(int i=1;i<=r;i++){
     17             for(int j=1;j<=c;j++){
     18                 cin>>ptr[i][j];
     19             }
     20         }
     21         string ar[100],ac[100];
     22         int    ir=1,   ic=1;
     23         for(int i=1;i<=r;i++){//这里将行连成串 ,并且用一个数组存起来 
     24             string temp;
     25             for(int j=1;j<=c;j++){
     26                 temp=temp+ptr[i][j];
     27             }
     28             ar[ir++]=temp;
     29         }
     30         for(int i=1;i<=c;i++){//这里将列连成串  并且用一个数组存起来 
     31             string temp;
     32             for(int j=1;j<=r;j++){
     33                 temp=temp+ptr[j][i];
     34             }
     35             ac[ic++]=temp;
     36         }
     37         cin>>num;
     38         cout<<"Word search puzzle #"<<g<<":"<<endl;
     39         g++;
     40         for(int i=0;i<num;i++){
     41             cin>>arr;
     42             int front=0;//记录寻找的方向是那个
     43             int x,y;//第一个字母出现的坐标 
     44             int f=0;//是否找到的标记
     45             if(f==0){//行  顺   
     46                 for(int j=1;j<ir;j++){//遍历每一个行元素 
     47                     string temp;
     48                     while(temp.length()<=10000){
     49                         temp=temp+ar[j];
     50                     }
     51                     //下面开始寻找
     52                     int dis=temp.find(arr);
     53                     if(dis!=-1){//找到 下面就是要记录第一个位置出现的 行 和 列的坐标 
     54                         x=j;
     55                         y=dis+1;
     56                         f=1;//标记找到
     57                         front=1;//向右 
     58                         break; 
     59                     }else{}//表示没有找到 
     60                 }
     61             } 
     62             if(f==0){//行 逆 
     63                 for(int j=1;j<ir;j++){//遍历每一个行元素 
     64                     string temp;
     65                     string s(ar[j].rbegin(),ar[j].rend());
     66                     while(temp.length()<=10000){
     67                         temp=temp+s;
     68                     }
     69                     int dis=temp.find(arr);
     70                     if(dis!=-1){//找到  下面的难点就是记录出现的位置 
     71                         x=j;
     72                         y=s.length()-1-dis+1;
     73                         f=1;
     74                         front=2;//向左 
     75                         break;
     76                     }else{}//没有 
     77                 }
     78             }
     79             if(f==0){//列 顺(从上往下) 
     80                 for(int j=1;j<ic;j++){//遍历每一个列元素 
     81                     string temp;
     82                     while(temp.length()<=10000){
     83                         temp=temp+ac[j];
     84                     }
     85                     int dis=temp.find(arr);
     86                     if(dis!=-1){//找到  现在主要是要确定行和列的坐标 
     87                         x=dis+1;
     88                         y=j;
     89                         front=3;//向下 
     90                         f=1;
     91                         break;
     92                     }else{}//没找到 
     93                 } 
     94             } 
     95             if(f==0){//列 逆 (从下往上) 
     96                 for(int j=1;j<ic;j++){//遍历每一个 
     97                     string temp;
     98                     string s(ac[j].rbegin(),ac[j].rend());
     99                     while(temp.length()<=10000){
    100                         temp=temp+s;
    101                     }
    102                     int dis=temp.find(arr);
    103                     if(dis!=-1){//找到 现在主要确定第一个字母的行和列 
    104                         x=s.length()-1-dis+1;
    105                         y=j;
    106                         f=1;
    107                         front=4;//向下 
    108                         break;
    109                     }else{}//没找到 
    110                 }
    111             } 
    112             if(front==1) cout<<"R ";
    113             if(front==2) cout<<"L ";
    114             if(front==3) cout<<"D ";
    115             if(front==4) cout<<"U ";
    116             cout<<x<<" "<<y<<" ";
    117             cout<<arr<<endl;
    118         }//数据输入完毕,下面开始处理数据
    119         cout<<endl;
    120     }
    121     return 0;
    122 }
    View Code
  • 相关阅读:
    九月二十日
    九月十九日
    九月十八日
    九月十七日
    九月十六日
    大三第一周学习后的感悟及本学期计划
    阅读笔记09梦断代码
    阅读笔记08-梦断代码
    对搜狗现如今的用法进行评述
    寻找水王
  • 原文地址:https://www.cnblogs.com/blogxsc/p/12602853.html
Copyright © 2011-2022 走看看