zoukankan      html  css  js  c++  java
  • 2020.3.28 UCF Local Programming Contest 2016 解题+补题报告

    A Majestic 10

     1.题意

      给定三个数,判断有几个数不小于10。

     2.题解

      逐个判断,记录不小于10的数字的数量。

     3.代码

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int n;
     4 int main(){
     5     cin>>n;
     6     while(n--){
     7         int x,sum=0;
     8         for(int i=1;i<=3;i++){
     9             cin>>x;
    10             if(x>=10)
    11                 sum++;
    12             cout<<x;
    13             if(i!=3)
    14                 cout<<' '; 
    15         }
    16         cout<<'
    ';
    17         if(sum==0)
    18             cout<<"zilch";
    19         else if(sum==1)
    20             cout<<"double";
    21         else if(sum==2)
    22             cout<<"double-double";
    23         else
    24             cout<<"triple-double";
    25         cout<<'
    '<<'
    ';
    26     }
    27     
    28     return 0;
    29 }

    B SSPhoneme Palindrome

     1.题意

      判断回文字符串,但题目给定了n对可以相互替换的字母。

     2.题解

      把可以替换的字母全变成一致的一个字母,再判断回文串。

     3.代码

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int t;
     4 bool pal(string s){
     5     for(int i=0,j=s.size()-1;i<j;i++,j--){
     6         if(s[i]!=s[j])
     7             return false;
     8     }
     9     return true;
    10 }
    11 int main(){
    12     cin>>t;
    13     for(int q=1;q<=t;q++){
    14         cout<<"Test case #"<<q<<':'<<endl;
    15         int n;
    16         cin>>n;
    17         char a[15],b[15];
    18         for(int i=0;i<n;i++){
    19             cin>>a[i];
    20             getchar();
    21             cin>>b[i];
    22         } 
    23         int k;
    24         cin>>k;
    25         while(k--){
    26             string s;
    27             cin>>s;
    28             cout<<s<<' ';
    29             for(int i=0;i<s.size();i++){
    30                 for(int j=0;j<n;j++){
    31                     if(s[i]==a[j]){
    32                         s[i]=b[j];
    33                         break;
    34                     }                 
    35                 }
    36             }
    37             if(pal(s))
    38                 cout<<"YES"<<endl;
    39             else
    40                 cout<<"NO"<<endl;
    41         }
    42         cout<<'
    ';
    43     }
    44     
    45     return 0;
    46 }

    Don’t Break the Ice

     1.题意

      给定一个方阵,移动会使这一步所在的行和列“击碎”,如果在这之前,这一步的行和列都已经被“击碎”,就认定这一步为无效的。

     2.题解

      分别用两个一维数组储存行和列的状态。

     3.代码

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int t;
     4 int main(){
     5     cin>>t;
     6     for(int q=1;q<=t;q++){
     7         cout<<"Strategy #"<<q<<':'<<' ';
     8         int size,n,sum=0;
     9         cin>>size>>n;
    10         int a[100]={0},b[100]={0};
    11         while(n--){
    12             int x,y;
    13             cin>>x>>y;
    14             if(a[x]==1&&b[y]==1)
    15                 sum++;
    16             a[x]=1,b[y]=1;
    17         } 
    18         cout<<sum<<endl;
    19         cout<<'
    ';
    20     }
    21     
    22     return 0;
    23 }

    D Wildest Dreams

     1.题意

      给定一张专辑,女儿喜欢其中的一首,当女儿在车里时,重复播放她喜欢的那首,当她离开后,顺序播放下一首。计算父亲听女儿喜欢的那首歌的总时间,奇数段为女儿待在车里的时间。

     2.题解

      模拟。

     3.代码

     1 #include<bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 ll t;
     5 int main(){
     6     cin>>t;
     7     for(ll q=1;q<=t;q++){
     8         cout<<"CD #"<<q<<':'<<endl;
     9         ll n,x;
    10         cin>>n>>x;
    11         ll len[30];
    12         ll  sum=0;
    13         for(ll i=1;i<=n;i++){
    14             cin>>len[i];
    15             sum+=len[i]; 
    16         }
    17         ll day;
    18         cin>>day;
    19         for(ll i=1;i<=day;i++){
    20             ll k;
    21             cin>>k;
    22             ll ans=0;
    23             ll rem=0;
    24             for(ll j=1;j<=k;j++){
    25                 ll time;
    26                 cin>>time;
    27                 if(time==0)
    28                     continue;
    29                 if(j%2==1){
    30                     rem=0;
    31                     if(time==len[x])
    32                         ans+=time;
    33                     else if(time<len[x]){
    34                         ans+=time;
    35                         rem=len[x]-time;
    36                     }
    37                     else{
    38                         ans+=time;
    39                         rem=len[x]-(time%len[x]);
    40                     }
    41                 }
    42                 else{
    43                     if(time<=rem){
    44                         ans+=time;
    45                     }
    46                     else{
    47                         ans+=rem;
    48                         time-=rem;
    49                         ll w=0,e=0;
    50                         w=time/sum;
    51                         e=time%sum;
    52                         ans+=(w*len[x]);
    53                         if(e>sum-len[x])
    54                             ans+=(e-(sum-len[x]));
    55                     }
    56                 }
    57             }
    58             cout<<ans<<endl;
    59         }
    60         cout<<'
    ';
    61     }
    62     
    63     return 0;
    64 }
  • 相关阅读:
    win32: 静态控件(Static)
    malloc() 和 calloc()有啥区别
    win32: WM_PAINT 实现双缓冲缓图
    char 与 unsigned char的本质区别
    iconv: iconv_open(pToCharset, pFromCharset); 的附加参数//IGNORE
    c语言: 生成随机数
    深圳市住房公积金管理中心
    利用latex制作个人简历
    分布式系统概念与设计中文版(第三版)
    数据结构-红黑树
  • 原文地址:https://www.cnblogs.com/lvguapi/p/12597534.html
Copyright © 2011-2022 走看看