首页 > 其他 > 详细

2020.03.28 UCF Local Programming Contest 2016

时间:2020-04-02 21:58:55      阅读:69      评论:0      收藏:0      [点我收藏+]

A题:

题意:

给你三个数,让他们与10比较,统计个数,比较简单,但要注意输出格式

代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
    int n,m;
    int a,b,c;
    int ans = 0;
    cin>>n;
    for(int i=0;i<n;i++){
	    ans=0;
	    cin>>a>>b>>c;
	    if(a>=10)
	    	    ans++;
	    if(b>=10)
		    ans++;
	    if(c>=10)
	    	    ans++;
	    if(ans==0)
		    printf("%d %d %d\nzilch\n\n",a,b,c);
	    else if(ans==1)
		    printf("%d %d %d\ndouble\n\n",a,b,c);
	    else if(ans==2)
		    printf("%d %d %d\ndouble-double\n\n",a,b,c);
	    else if(ans==3)
		    printf("%d %d %d\ntriple-double\n\n",a,b,c);
    }
    return 0;
}

B题:

题意:

给出几对字符对,表明这两个字符可以互换,问下面给的字符串在替换完以后是不是回文字符串

思路:

用map标记可以互换的字符对,然后对给的字符串进行一一替换,最后检查是否为回文

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
using namespace std;
const long long N = 1e9 + 7;
typedef long long ll;
map <char,int> ma;
char q = ‘a‘;

int main()
{

    int t;
    cin >> t;
    getchar();
    for(int i = 1;i <= t;i++)
    {
        for(int j = 0;j < 26;j++)
            ma[q+j] = j;

        int m;
        cin >> m;
        getchar();
        for(int j = 0;j < m;j++)
        {
            char a,b;
           // scanf("%c %c",&a,&b);
           cin >> a;
           getchar();
           cin >> b;
            getchar();
            ma[a] = ma[b];
        }
        int n;
        cin >> n;
        getchar();
        string s[110];
        for(int j = 0;j < n;j++)
        {
            cin >> s[j];
            getchar();
        }
        printf("Test case #%d:\n",i);
        for(int j = 0; j < n;j++)
        {

            int findnum = 1;
            int len = s[j].size();
            for(int k = 0;k < len / 2;k++)
            {
                if(ma[  s[j][k]  ] != ma[  s[j][len - k - 1]  ])
                {
                    findnum = 0;
                    break;
                }
            }
            if(findnum)
                cout << s[j] << " " << "YES" << endl;
            else
                cout << s[j] << " " << "NO" << endl;
        }
        cout << endl;


    }


    return 0;
}

C题:

题意:

每敲掉一个冰块,改变其状态后判断与之相关的行列上的所有冰块,若有掉落的冰块(加入队列)继续改变判断即可。

代码:

include

#include <algorithm>
using namespace std;

int n, a, t, x, y, l[150], r[150], index= 1;
int main(){
	
	
	cin>>n;
	while(n--){
		int count = 0;
		cin>>a>>t;
		for(int i = 1; i <= a;i++){
			l[i]= i;
			r[i]= i;
		}
		while(t--){
			cin>>x>>y;
			if(l[x]==0&&r[y]==0){
				count++;
			
			}
			l[x]=0;r[y]=0;	
		}
		cout<<"Strategy #"<<index++<<": "<<count<<endl;
		cout<<endl;
	} 
	return 0;
}

E题:

题意:

给出一个n*m的字符矩阵,查找字符串,可以上下左右的找,并且边界不会停止会接着找

思路:

先匹配第一个字符,然后向四个方向查找

代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
char s[200][200];
int r,c;
int R(char *ss,int j,int t){
	int rc=t;
	int len = strlen(ss);
	for(int i=0;i<len;i++){
		if(ss[i]!=s[j][rc])
			return 0;
		rc++;
		if(rc == c)
			rc = 0;
	}
	cout<<"R "<<j+1<<" "<<t+1<<" "<<ss<<endl;
	return 1;
}
int L(char *ss,int j,int t){
	int rc=t;
	int len = strlen(ss);
	for(int i=0;i<len;i++){
		if(ss[i]!=s[j][rc])
			return 0;
		rc--;
		if(rc == -1)
			rc = c-1;
	}
	cout<<"L "<<j+1<<" "<<t+1<<" "<<ss<<endl;
	return 1;
}
int U(char *ss,int j,int t){
	int rr=j;
	int len = strlen(ss);
	for(int i=0;i<len;i++){
		if(ss[i]!=s[rr][t])
			return 0;
		rr--;
		if(rr == -1)
			rr = r-1;
	}
	cout<<"U "<<j+1<<" "<<t+1<<" "<<ss<<endl;
	return 1;
}
int D(char *ss,int j,int t){
	int rr=j;
	int len = strlen(ss);
	for(int i=0;i<len;i++){
		if(ss[i]!=s[rr][t])
			return 0;
		rr++;
		if(rr == r)
			rr = 0;
	}
	cout<<"D "<<j+1<<" "<<t+1<<" "<<ss<<endl;
	return 1;
}
int pd(char *ss,int j,int t){
	if(R(ss,j,t))
		return 1;
	if(D(ss,j,t))
		return 1;
	if(L(ss,j,t))
		return 1;
	if(U(ss,j,t))
		return 1;
	return 0;
}
int main() {
	int n,m;
	cin>>n;
	char ss[1000];
	char a;
	for(int i=1;i<=n;i++){
		cin>>r>>c;
		for(int j=0;j<r;j++){
			scanf("%s",&s[j]);
		}
		cin>>m;
		printf("Word search puzzle #%d:\n",i);
		for(int q=0;q<m;q++){
			memset(ss,‘0‘,sizeof(ss));
			scanf("%s",&ss);
			int flag = 0;
			for(int j=0;j<r;j++){
				for(int t=0;t<c;t++){
					if(s[j][t]==ss[0]){
						flag = pd(ss,j,t);
					}
					if(flag == 1)
						break;
				}
				if(flag == 1)
					break;
			}	
		}
		cout<<endl;
	}
	return 0;
}

F题:

题意:

给你一堆点,找满足要求的点的组数

思路:

循环枚举任意两个点构成的线段,把该线段作为线段 AB。枚举所有的点,判断该点是否是线段 AB 的中点,如果是,则该点作为点 M。如果找到了点 M,再次枚举所有的点,寻找点 C 是否存在, 判断条件:|AB| = |CM| 且 AB ⊥ CM

代码:

include

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
using namespace std;
const long long N = 1e9 + 7;
typedef long long ll;
struct point
{
    double x;
    double y;

}p[55];
double X[3];
double Y[3];
bool fin(int j,int k,int l)
{
    if( (p[k].y - p[j].y)*(p[l].x - p[k].x)  == (p[l].y - p[k].y)*(p[k].x - p[j].x) )
        return true;
    else
        return false;
}
bool judge(int h)
{
    if(Y[0] == Y[1]&&Y[1] == Y[2]&&p[h].x == X[1])
    {
       if( fabs(p[h].y-Y[1]) == X[2] - X[0] )
            return true;
       else
            return false;
    }
    if(X[0] == X[1]&&X[1] == X[2]&&p[h].y == Y[1])
    {
       if( fabs(p[h].x-X[1]) == Y[2] - Y[0] )
            return true;
       else
            return false;
    }
    if(Y[0] == Y[1]&&Y[1] == Y[2]&&Y[1] == p[h].y)
        return false;
    if(X[0] == X[1]&&X[1] == X[2]&&X[1] == p[h].x)
        return false;
    if( (Y[1]-p[h].y) * (Y[2]-Y[0]) ==  -(X[1] - p[h].x) * (X[2] - X[0])  )
    {
        if( (Y[1]-p[h].y)*(Y[1]-p[h].y) + (X[1] - p[h].x)*(X[1] - p[h].x) - (Y[2]-Y[0])*(Y[2]-Y[0]) - (X[2] - X[0])*(X[2] - X[0]) <= 0.000001)
        {

             return true;
        }
    }

    else
        return false;
}
int main()
{
    int t;
    cin >> t;
    for(int i = 1;i <= t;i++)
    {
        int n;
        ll num = 0;
        cin >> n;
        for(int j = 0;j < n;j++)
            cin >> p[j].x >> p[j].y;
        for(int j = 0;j < n-2;j++)
        {
            for(int k = j+1;k < n-1;k++)
            {
                for(int l = k+1;l < n;l++)
                {
                    if(fin(j,k,l))
                    {

                        X[0] = p[j].x;
                        X[1] = p[k].x;
                        X[2] = p[l].x;
                        Y[0] = p[j].y;
                        Y[1] = p[k].y;
                        Y[2] = p[l].y;
                        sort(X,X+3);
                        sort(Y,Y+3);
                        if( X[0]+X[2] == 2*X[1]  )
                        {
                            for(int h = 0;h < n;h++)
                            {
                                if(h == j || h == k || h == l)
                                    continue;
                                if(judge(h))
                                    num++;
                            }
                        }
                    }

                }
            }

        }
        printf("Set #%d: %lld\n\n",i,num);


    }
    return 0;
}

2020.03.28 UCF Local Programming Contest 2016

原文:https://www.cnblogs.com/pioneerjiesen/p/12622464.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!