UCF Local Programming Contest 2016(2020-03-28)

原题地址:https://www.jisuanke.com/contest/7194?view=challenges

A. Majestic 10

水题

AC代码:

N = int(input())
for i in range(N):
    lst = list(map(int, input().strip().split()))
    dc = 0
    for j in range(3):
        if lst[j] >= 10:
            dc += 1
    print(lst[0], lst[1], lst[2])
    if dc == 0:
        print('zilch')
    elif dc == 1:
        print('double')
    elif dc == 2:
        print('double-double')
    elif dc == 3:
        print('triple-double')
    print()
View Code

B. Phoneme Palindromes

题意:判断是否是回文,另外会给定几组相对应得字符。

思路:用map存储一一对应的字母

AC代码:

#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
#define ll long long
int main(){    
    ll n,p,q;
    string ptr1;
    char c1,c2;
    cin>>n;
    int num=1;
    while(n--){
        cin>>p;
        map<char,char> mp;
        for(int i=0;i<p;i++){
            cin>>c1>>c2;
            mp[c1]=c2;
        }
        cin>>q;
        cout<<"Test case #"<<num<<":"<<endl;
        num++;
        for(int i=0;i<q;i++){//这是判断的 
            cin>>ptr1;
            string pr=ptr1;//原始 
            string ptr2(ptr1.rbegin(),ptr1.rend());
            if(ptr1==ptr2){
                cout<<pr<<" "<<"YES"<<endl;
            }else{
                for(int j=0;j<ptr2.length();j++){
                    if(mp.count(ptr2[j])!=0){//表示存在 
                        ptr2[j]=mp[ptr2[j]];
                    }
                }
                for(int j=0;j<ptr1.length();j++){
                    if(mp.count(ptr1[j])!=0){
                        ptr1[j]=mp[ptr1[j]];
                    }
                }
                if(ptr1==ptr2){
                    cout<<pr<<" "<<"YES"<<endl;
                }else{
                    cout<<pr<<" "<<"NO"<<endl;
                }
            }
        }
        cout<<endl;
    }
    return 0;
}
View Code

C. Don't Break the Ice

题意:敲掉所给点的冰块,只有冰块所在的行或列完整冰块才存在,问有多少准备敲击的冰块是不存在的

思路:用数组记录每行每列冰块是否完整,如果敲击冰块的列和行都是不完整的则记录

AC代码:

#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<list>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const int maxn = 300;
const ll mod = 1e9+7;
ll xnode[maxn];
ll ynode[maxn];
int main()
{
    int N;
    cin>>N;
    {
        for(int k=1;k<=N;k++)
        {
            
            memset(xnode,1,sizeof(xnode));
            memset(ynode,1,sizeof(ynode));
            int n,m;
            cin>>n>>m;
            int count = 0;
            for(int i=0;i<m;i++)
            {
                int x,y;
                cin>>x>>y;
                if(xnode[x]==0&&ynode[y]==0)
                {
                    count++;
                }
                else
                {
                    xnode[x]=0;
                    ynode[y]=0;
                }
            }
            cout<<"Strategy #"<<k<<": ";
            cout<<count<<endl<<endl;
        }
    }
    return 0;
}
    
View Code

D. Wildest Dreams

题意:给定每段CD的时间,和女儿是否在的时间段,问总共听女儿喜欢的CD多长时间

思路:直接模拟,注意:时间结束若女儿刚好离开,歌曲按顺序播放,不会从开头听,女儿离开,若歌曲没听完还会继续听:

AC代码:

#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<list>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const int maxn = 150;
const ll mod = 1e9+7;
ll node[maxn];
map<char,char> mp;
int main()
{
    int T;
    cin>>T;
    for(int K=1;K<=T;K++)
    {
        int k,t;
        cin>>t>>k;
        int Sum = 0;
        for(int i=1;i<=t;i++)
        {
            cin>>node[i];
            Sum+=node[i];
        }
        int n;
        cin>>n;
        printf("CD #%d:\n",K);
        while(n--)
        {
            int tsum = 0;
            int d;
            cin>>d;
            int dt[150];
            for(int i=1;i<=d;i++)
            {
                cin>>dt[i];
            }
            for(int i=1;i<=d;i++)
            {
                if(i%2==1)
                {
                    tsum+=dt[i];
                    int tt = dt[i]%node[k];
                    if(tt==0) continue;
                    else
                    {
                        int ts = node[k]-tt;
                        if(i!=d)
                        {
                            if(dt[i+1]-ts>=0)
                            {
                                tsum+=ts;
                                dt[i+1]-=ts;
                            }
                            else
                            {
                                tsum+=dt[i+1];
                                dt[i+1]=0;
                            }
                        }
                    }
                }
                else
                {
                    int t = dt[i]/Sum;
                    tsum+=t*node[k];
                    if(dt[i]%Sum!=0)
                    {
                        int ttt =dt[i]%Sum;
                        int tss = ttt-(Sum-node[k]);
                        if(tss>0) tsum+=tss; 
                    }
                    
                }
            }
            cout<<tsum<<endl;
        }
        cout<<endl;
        
    }
    return 0;
}
    
View Code

E. Loopy Word Search

题意:给定字母方格和单词,找到单词首字母所在位置和方向

思路:暴力模拟;因为题意为通过首字母查找位置,可以记录字母方格中每个字母的所有位置,通过所给单词的首字母可以确定查找的范围,然后想上下左右四个方向查找符合题意得答案。

AC代码:

#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<list>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const int maxn = 150;
const ll mod = 1e5+10;

char s[110][110];
typedef struct NODE{
    int x;
    int y;
}N;
vector<N> a[26];//记录字母网格中,每个字母所在得位置 
int main()
{
    int Q;
    cin>>Q;
    for(int K=1;K<=Q;K++)
    {    
        for(int i=0;i<26;i++)
        {
            a[i].clear();
        }
        int n,m;
        cin>>n>>m;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                cin>>s[i][j];
                N t;
                t.x = i;
                t.y = j;
                a[s[i][j]-'A'].push_back(t);//按记录纪录位置 
            }
        }
        
        
        int p;
        cin>>p;
        printf("Word search puzzle #%d:\n",K);
        string q;
        for(int i=0;i<p;i++)
        {
            cin>>q;
            
            int count = a[q[0]-'A'].size();//记录单词首字母 在网格中出现得次数,再遍历 
            for(int j=0;j<count;j++)
            {
                N t = a[q[0]-'A'][j];
                int flag = 1;
                //四个方向遍历 
                //
                for(int e = (t.x-1+n)%n,f = 1;f<q.length();f++,e = (e-1+n)%n)
                {
                    if(q[f]!=s[e][t.y])
                    {
                        flag = 0;
                        break;
                    }
                 } 
                 if(flag == 1)
                 {
                     printf("U %d %d ",t.x+1,t.y+1);
                     cout<<q<<endl;
                     break;
                 }
                flag = 1;
                //
                for(int e =(t.x+1)%n,f=1;f<q.length();f++,e = (e+1)%n) 
                {
                    if(q[f]!=s[e][t.y])
                    {
                        flag = 0;
                        break;
                    }
                    
                }
                if(flag==1)
                {
                     printf("D %d %d ",t.x+1,t.y+1);
                    cout<<q<<endl;
                    break;
                }
                flag = 1;
                //
                for(int e = (t.y-1+m)%m,f=1;f<q.length();f++,e = (e-1+m)%m)
                {
                    if(q[f]!=s[t.x][e])
                    {
                        flag = 0;
                        break;
                    }
                    
                }
                if(flag==1)
                {
                    printf("L %d %d ",t.x+1,t.y+1);
                    cout<<q<<endl;
                    break;
                 } 
                 flag = 1;
                //
                for(int e = (t.y+1)%m,f=1;f<q.length();f++,e = (e+1)%m)
                {
                    if(q[f]!=s[t.x][e])
                    {
                        flag = 0;
                        break;
                    }
                }
                if(flag==1)
                {
                     printf("R %d %d ",t.x+1,t.y+1);
                     cout<<q<<endl;
                     break;
                }
            }    
             
            
        }
        
        cout<<endl;
    }
    
    return 0;
}    
View Code

 

posted @ 2020-04-05 20:34  精神小伙儿  阅读(179)  评论(0编辑  收藏  举报