zoukankan      html  css  js  c++  java
  • USACO Section 1.1(简单模拟)

    你的飞碟在这儿Your Ride Is He…

    题意:给定两个长度不超过6的仅含有大写字母的字符串,判断两个串分别的乘积mod47是否相等(A是1,B是2,...,Z是26).

    直接按照题意来做就行了.

    #include<bits/stdc++.h>
    using namespace std;
    char a1[10],b1[10];
    int a[101],b[101];
    int main(){
    	gets(a1);gets(b1);
    	int la=strlen(a1);
    	int lb=strlen(b1);
    	for(int i=0;i<la;i++)a[i+1]=a1[i]-64;
    	for(int i=0;i<lb;i++)b[i+1]=b1[i]-64;
    	int tota=1,totb=1;
    	for(int i=1;i<=la;i++)tota*=a[i];
    	for(int i=1;i<=lb;i++)totb*=b[i];
    	if(tota%47==totb%47) cout<<"GO";
    	else cout<<"STAY";
    	return 0;
    }
    

    贪婪的送礼者Greedy Gift Givers

    题意:对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少。在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人。然而,在任何一群朋友中,有些人将送出较多的礼物(可能是因为有较多的朋友),有些人有准备了较多的钱。给出一群朋友,没有人的名字会长于 14 字符,给出每个人将花在送礼上的钱,和将收到他的礼物的人的列表,请确定每个人收到的比送出的钱多的数目。

    直接按照题意模拟来做,可以借助map来让序号与人名对应起来.

    //#include<bits/stdc++.h>
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    #include<map>
    using namespace std;
    inline int read(){
        int x=0,o=1;char ch=getchar();
        while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
        if(ch=='-')o=-1,ch=getchar();
        while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
        return x*o;
    }
    int ans[20];
    map<string,int>Map;
    map<int,string>Mapp;
    int main(){
    	int n=read();
    	for(int i=1;i<=n;++i){
    		string s;cin>>s;
    		Map[s]=i;Mapp[i]=s;
    	}
    	for(int i=1;i<=n;++i){
    		string s;cin>>s;
    		int sum=read(),num=read(),ave;
    		if(!sum||!num)continue;
    		ans[Map[s]]-=sum;
    		if(sum%num)ave=floor(sum/num),ans[Map[s]]+=sum-num*ave;
    		else ave=sum/num;
    		for(int j=1;j<=num;++j){
    			cin>>s;ans[Map[s]]+=ave;
    		}
    	}
    	for(int i=1;i<=n;++i){
    		cout<<Mapp[i]<<" "<<ans[i]<<endl;
    	}
        return 0;
    }
    

    黑色星期五Friday the Thirteenth

    题意:13号又是一个星期五。13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数。给出N年的一个周期,要求计算1900年1月1日至1900+N-1年12月31日中十三号落在周一到周日的次数,N为正整数且不大于400.这里有一些你要知道的:1、1900年1月1日是星期一.2、4,6,11和9月有30天.其他月份除了2月都有31天.闰年2月有29天,平年2月有28天.3、年份可以被4整除的为闰年(1992=4*498 所以 1992年是闰年,但是1990年不是闰年).4、以上规则不适合于世纪年。可以被400整除的世纪年为闰年,否则为平年。所以,1700,1800,1900和2100年是平年,而2000年是闰年.

    直接根据题意模拟,注意一些大月小月2月和闰年平年的细节就行了.

    //#include<bits/stdc++.h>
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    #include<map>
    using namespace std;
    inline int read(){
        int x=0,o=1;char ch=getchar();
        while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
        if(ch=='-')o=-1,ch=getchar();
        while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
        return x*o;
    }
    int ans[10];
    inline int pd(int n){
    	if(n%100!=0&&n%4==0)return 1;
    	if(n%100==0&&n%400==0)return 1;
    	return 0;
    }
    inline int PD(int n){
    	if(n==0)return 2;
    	if(n==2)return 0;
    	if(n==4||n==6||n==9||n==11)return 1;
    	return 2;
    }
    int main(){
    	int n=read();
    	int last=13%7;++ans[last];
    	int year=1900,month=1,bj1=0,bj2=2;
    	for(int i=2;i<=n*12;++i){
    		++month;
    		if(month==13){
    			month=1;++year;
    			bj1=pd(year);
    		}
    		bj2=PD(month-1);
    		if(bj2==0){
    			if(bj1==0)++ans[last];	
    			else{
    				++last;if(last==8)last=1;
    				++ans[last];
    			}
    		}
    		if(bj2==1){
    			last+=2;last=(last+7)%7;if(last==0)last=7;
    			++ans[last];
    		}
    		if(bj2==2){
    			last+=3;last=(last+7)%7;if(last==0)last=7;
    			++ans[last];
    		}
    	}
    	cout<<ans[6]<<" "<<ans[7]<<" ";
    	for(int i=1;i<=5;++i)cout<<ans[i]<<" ";
    	cout<<endl;
        return 0;
    }
    

    坏掉的项链Broken Necklace

    题意:给定一条由r,b,w三种小写字母构成的长度为n的项链,求出从哪里断开项链然后从一端开始收集同颜色的珠子直到你遇到一个不同的颜色珠子,在另一端做同样的事(颜色可能与在这之前收集的不同).确定应该在哪里打破项链来收集到最大数目的珠子。注意w既可以看做r,也可以看作b.求出最大数目即可.

    分析:首先断环为链的基本操作是使得字符串倍长,然后从小到大枚举断开的位置,但是因为本题中我们要往两端找,所以我们要三倍长原来的字符串,然后从中间那个字符串开始,分别向两头判断最长长度即可.

    #include<bits/stdc++.h>
    using namespace std;
    string a;
    int n,ans=-1;
    int f(int x){
        int s=0;
        char a1=a[x];
        char b2=a[x+1];
        for(int i=x;;i--){
            if(a[i]==a1)s++;
            else if(a[i]=='w') s++;
            else break;
        }
        for(int i=x+1;;i++){
            if(a[i]==b2)s++;
            else if(a[i]=='w')s++;
            else break;
        }
        return s;
    }
    int main(){
        cin>>n;
        cin>>a;
        a=a+a+a;
        for(int i=n;i<2*n;i++){
            if(a[i]==a[i+1]) continue;
            if(a[i]=='w'){
                a[i]='r';
                ans=max(ans,f(i));
                a[i]='b';
                ans=max(ans,f(i));
                a[i]='w';
            }
            ans=max(ans,f(i));
        }
        ans=min(ans,n);
        if(ans==-1) ans=n;
        cout<<ans<<endl;
        return 0;
    }
    
  • 相关阅读:
    数据结构-树与二叉树-思维导图
    The last packet successfully received from the server was 2,272 milliseconds ago. The last packet sent successfully to the server was 2,258 milliseconds ago.
    idea连接mysql报错Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property
    redis学习笔记
    AJAX校验注册用户名是否存在
    AJAX学习笔记
    JSON学习笔记
    JQuery基础知识学习笔记
    Filter、Listener学习笔记
    三层架构学习笔记
  • 原文地址:https://www.cnblogs.com/PPXppx/p/11262664.html
Copyright © 2011-2022 走看看