UCF Local Programming Contest 2015 A~~H

2020-09-10 21:43:16 浏览数 (1)

题目链接

A 水题:

代码语言:javascript复制
#include<bits/stdc  .h>
#define inf 0x3f3f3f3f

using namespace std;

int a[15];

int main(){
    int t;
	cin>>t;
	while(t--){
		bool flag1 =0;
		bool flag2 =0;
	for(int i=1;i<=10;i  ){
		cin>>a[i];
		if(a[i] == 18) flag1 = 1;
		if(a[i] == 17) flag2 = 1;
	}
	for(int i=1;i<10;i  )
	cout<<a[i]<<" ";
	cout<<a[10]<<endl;
	if(flag1 && flag2) cout<<"both"<<endl;
	if(!flag1 && !flag2) cout<<"none"<<endl;
	if(!flag1 && flag2) cout<<"zack"<<endl;
	if(flag1 && !flag2) cout<<"mack"<<endl;
	cout<<endl;
		
	}	
	return 0;
}

B 水题

代码语言:javascript复制
#include<bits/stdc  .h>

using namespace std;



int main(){
	int t;
	cin>>t;
	while(t--){
		bool flag1 = 0;
		bool flag2 = 0;
     int a,b,c;
     int x,y,z;
     cin>>a>>b>>c>>x>>y>>z;
     int num1 = a b c;
     int num2 = x y z;
     if(num1 > num2) flag1 = 1;
     
     if(a > x) flag2 = 1;
	 else if(a == x && b > y) flag2 = 1;
	 else if(a == x && b == y && c > z) flag2 = 1;
	 
	 else
	   flag2 = 0;
	   
	   cout<<a<<" "<<b<<" "<<c<<" "<<x<<" "<<y<<" "<<z<<endl;
	if(flag1 && flag2) cout<<"both"<<endl;
	if(!flag1 && !flag2) cout<<"none"<<endl;
	if(!flag1 && flag2) cout<<"color"<<endl;
	if(flag1 && !flag2) cout<<"count"<<endl;
	
	cout<<endl;
}
	return 0;
}

C 水题:

代码语言:javascript复制
#include<bits/stdc  .h>
using namespace std;
typedef long long ll;
const int N=500010;

    
int main(){
	int t;
    cin>>t;
    while(t--){

    int xx=1;
    int n,sum,m;
    cin>>n>>sum>>m;
    printf("Practice #%d: %d %dn",xx  ,n,sum);
    int sum1=sum;

    while(m--)
    {
        int x,y;	cin>>x;
        if(x<sum)
        {
            sum-=x;
        }
        else
        {
            while(sum<=x)
                sum=sum*2;
            sum-=x;
        }
        cout<<x<<" "<<sum<<endl;
    }
    cout<<endl;
}
	return 0;
}

D.

代码语言:javascript复制
#include<bits/stdc  .h>
using namespace std;
typedef long long ll;
const int N=2e5 10;
ll ans;
int t,num[100];
int main()
{
	cin>>t;
	while(t--)
	{
		int n,m,x,s,aa[2000],bb[2000],c[2000];
		cin>>n>>x>>s;
		int l[2000],lr=0x3f3f3f3f,rr=0x3f3f3f3f;
		for (int i=1;i<=n;i  )
            cin>>aa[i]>>bb[i]>>c[i];
		vector<pair<int,int> > ve;
		m=0;
		for(int i=1;i<=n;i  ){
			if(bb[i]>=lr){
				l[i]=lr;
			}
			else{
				lr=bb[i];
				l[i]=bb[i];
			}

			if(c[i]>=rr)
                m =aa[i]*s;
			else{
				if(rr!=0x3f3f3f3f)
					ve.push_back({m,rr});
				rr=c[i];m=aa[i]*s;
			}
		 }
		if(m)
            ve.push_back({m,rr});

		ans=0;
		for(int i=1;i<=n;i  ){
			ans =(1ll*aa[i]*x*l[i]);
	
		}
		m=0;
		for(int i=0;i<ve.size();i  )
		{
			int d=ve[i].first,e=ve[i].second;
			
			int res=max((d-m 79),0)/80;
			ans =res*e;
			m=m res*80-d;
		}
		cout<<ans<<endl;
	}
	return 0;
 }

E 分情况讨论

代码语言:javascript复制
#include<bits/stdc  .h>

#define PI 3.14159265358979
using namespace std;


int main(){
	int t;
	cin>>t;
	while(t--){
		double z,y;
		cin>>z>>y;
		if(z >= 2*y){
		  printf("%.2lfn",PI*y*y);
		}
		else if( 4*y*y >= 2*z*z ){
			printf("%.2lfn",z*z);
		}
		else{
		 double st = (y*y)/2.0 * (PI/180.0)* 2 *(180.0*acos((z/2.0) * y)/PI )- (z*z/4.0 * sqrt(y*y-z*z/4.0))/2.0;
		 printf("%.2lfn",y*y - 4 * st);
		}
	}
	return 0;
} 

F

代码语言:javascript复制
#include<bits/stdc  .h>
using namespace std;
typedef long long ll;
string s;

int n,t,m;
int main()
{

	int T=1;
	cin>>t;
	while(t--){
		printf("String #%d: ",T  );
		cin>>s;
		int a[2000];
		for(int i=0;i<s.size();i  )
			if(s[i]=='?') a[i]=-1;
			else if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||'u'==s[i]||s[i]=='y') a[i]=0;
			else a[i]=1;
		int xx=-1;
		for(int i=0;i<s.size();i  )
			if(a[i]!=-1){
				xx=i;
			  	break;
			}

		ll ans=1;
		if(xx!=-1){
			for(int i=xx-1;i>=0;i--){
				if(a[i]==1-a[i 1])
                    continue;
				else if(a[i]==-1){
					ans=ans*(a[i 1]==0?20:6);
					a[i]=1-a[i 1];
				}
				else ans=0;
			}
			for(int i=xx 1;i<s.size();i  ){
				if(a[i]==1-a[i-1]) continue;
				else if(a[i]==-1){
					ans=ans*(a[i-1]==0?20:6);
					a[i]=1-a[i-1];
				}
				else ans=0;
			}
			cout<<ans<<endl;
		}
		else{
			int x=s.size()/2,y=s.size()-x;
			ll res1=1,res2=1;
			for(int i=0;i<x;i  ){
				res1*=6;
				res2*=20;
			}
			for(int i=0;i<y;i  ){
					res1*=20;
					res2*=6;
				}
			cout<<res1 res2<<endl;
		}
		cout<<endl; 
	}
	return 0;
 }

G

代码语言:javascript复制
#include<bits/stdc  .h>
using namespace std;
typedef long long ll;
const int N=2e5 10;

int main(){
    int t;cin>>t;
    int xx=1;
    while(t--){
        int flag=1;
        int d,n;cin>>d>>n;
        if(d-1>(n-1)*(n-1))
            printf("Grid #%d: impossiblen",xx  );
        else
            printf("Grid #%d: %dn",xx  ,((n-1) (n-1))*d);
        if(t)
            cout<<endl;
    }
    return 0;
}

H 样例过了,W

代码语言:javascript复制
#include<bits/stdc  .h>

using namespace std;

char a[102][102];
bool vis[102][102];
int main(){
	int t;
	cin>>t;
	int k = 1;
	while(t--){
		cout<<"Image#"<<" "<<k<<":"<<" ";
		for(int i=0;i<=100;i  ){
			for(int j=0;j<=100;j  ){
				a[i][j] = '.';
				vis[i][j] = 0;
			}
		}
		
		int x,y;
		cin>>x>>y;
		bool flag = 0;
		for(int i=1;i<=x;i  ){
			for(int j=1;j<=y;j  ){
				cin>>a[i][j];
				if(a[i][j] == '#')
				  flag = 1;
			}
		}
		if(!flag){
			cout<<"0"<<endl;
			cout<<endl;
			k  ;
			continue;
		}
		
		int num = 0;
		for(int i=1;i<=x;i  ){
			for(int j=1;j<=y;j  ){
				if(a[i][j] == '#'&&a[i][j 1] == '#'&&a[i-1][j 1] == '#'&&a[i 1][j 1] == '#'&&a[i][j 2] == '#'){
				if(vis[i][j]==0||vis[i][j 1]==0||vis[i-1][j 1]==0||vis[i 1][j 1]==0||vis[i][j 2]==0){
				
						  	num  ;
					      	vis[i][j] = 1;
					      	vis[i][j 1] = 1;
					      	vis[i-1][j 1] = 1;
					      	vis[i 1][j 1] = 1;
					      	vis[i][j 2] = 1;
					      }
						  }
				}
			}
		
		if(!num&&flag){
			cout<<"impossible"<<endl;
			cout<<endl;
			k  ;
			continue;
		}
		cout<<num<<endl;
		cout<<endl;
		k  ;
	}
	
}

大佬题解:DFS搜索加剪枝

0 人点赞