2019江西省赛ccpc题解

题号不分前后,后续接着补题,写一些自己感悟,及心得。
String
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6572
Avin has a string. He would like to uniform-randomly select four characters (selecting the same character is allowed) from it. You are asked to calculate the probability of the four characters being ”avin” in order.
Input
The first line contains n (1 ≤ n ≤ 100), the length of the string. The second line contains the string. To simplify the problem, the characters of the string are from ’a’, ’v’, ’i’, ’n’.
Output
Print the reduced fraction (the greatest common divisor of the numerator and denominator is 1), representing the probability. If the answer is 0, you should output “0/1”.

Sample Input
4
avin
4
aaaa
Sample Output
1/256
0/1

题面:要求字符串只有a,v,i,n四种字母,每次随机取四个,问取得avin的概率
a,v,i,n的概率是a,v,i,n出现的次数/字符串的长度的四次方
但是输出结果时需要约分,例如2/256,你要输出1/128。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<stack>
#include<string>
#define ll long long
#define rep(i,a,b)for(int i=a;i<=b;i++)
#define rep1(i,a,b)for(int i=a;i<b;i++)
#define rep2(i,a,b)for(int i=a;i>=b;i--)
#define rep3(i,a,b)for(int i=a;i>b;i--)
using namespace std;
const int maxn=1e5+10;
int n;
char c[1005];
int gcd(int a,int b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
int main(){
    while(~scanf("%d",&n)){
        int a1=0,a2=0,a3=0,a4=0;//分别统计四个字母出现的次数
        //也可以开一个int数组cnt[];cnt[c[i]-'a']++来统计字母出现的次数
        scanf("%s",c);
        int len=strlen(c);
        rep1(i,0,len){
            if(c[i]=='a')
                a1++;
            if(c[i]=='v')
                a2++;
            if(c[i]=='i')
                a3++;
            if(c[i]=='n')
                a4++;
        }
        //printf("%d%d%d%d\n",a1,a2,a3,a4);
        if(a1==0||a2==0||a3==0||a4==0){
            printf("0/1\n");
            continue;
        }
        int k=n*n*n*n;
        int m=a1*a2*a3*a4;
        int g=gcd(k,m);
        printf("%d/%d\n",m/g,k/g);
    }
    
}

Traffic
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6573
题面:有南北和东西走向的车,但是当东西车走的时候,南北向的必须等待,不然会造成交通堵塞,问需要等待多久使得交通不拥堵。

1 1
1
1
1 2
2
1 3
Sample Output
1
0
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<vector>
#define ll long long
#define inf 0x3f3f3f3f
#define rep(i,a,b)for(int i=a;i<=b;i++)
#define rep1(i,a,b)for(int i=a;i<b;i++)
#define rep2(i,a,b)for(int i=b;i>=a;i--)
using namespace std;
//const int maxn=2e5+5;
int n,m;
int a[1005],b[1005];
int main(){
 while(~scanf("%d%d",&n,&m)){
    rep(i,1,n)
    scanf("%d",&a[i]);
    rep(j,1,m)
    scanf("%d",&b[j]);
    sort(a+1,a+n+1);
    sort(b+1,b+m+1);
    int maxx=max(n,m);
    int ans=0;
    while(1){
        int fla=1;
        rep(i,1,maxx){
            rep(j,1,maxx){
                if(a[i]==b[j]){
                    fla=0;//标记相等
                    break;
                }
            }
            if(!fla)break;
        }
        if(fla){
            printf("%d\n",ans);
            break;
        }
        ans++;
        rep(j,1,m)
        b[j]+=1;//所有南北的车等待时间全部加1
     }
 }
    return 0;
}


D - Budget
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6575
题面:需要注意这并不是我们想象中的四舍五入到整数位,而是到小数第二位。要仔细读题!!
(这一题可以把小数乘一个数变为整数来做)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<vector>
#define ll long long
#define inf 0x3f3f3f3f
#define rep(i,a,b)for(int i=a;i<=b;i++)
#define rep1(i,a,b)for(int i=a;i<b;i++)
#define rep2(i,a,b)for(int i=b;i>=a;i--)
using namespace std;
const int maxn=2e5+5;
int t;
string s;
int main(){
    scanf("%d",&t);
    double ans=0;
    while(t--){
        cin>>s;
        int len=s.size();
        int k=s[len-1]-'0';//看小数最后一位
        //printf("%d\n",k);
        if(k<=4)
            ans+=-0.001*k;
        else if(k>=5&&k<=9)
            ans+=0.001*(10-k);
    }
    printf("%.3f\n",ans);
    return 0;
}

Worker
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6576
题解:是否存在一种情况使得 每个工厂每天处理的订单数相同 且所有人都要在工作 。从反面推,即可以找到同样的工作量,求他们的最小公倍数(此时,他们的工作量相等),然后将公倍数/工作效率相除,算出工人数相加,如果相加<=m并且能被m整数,可以输出yes,否则为no
ps:注意m数很大,需要用long long ;

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<vector>
#define ll long long
#define inf 0x3f3f3f3f
#define rep(i,a,b)for(int i=a;i<=b;i++)
#define rep1(i,a,b)for(int i=a;i<b;i++)
#define rep2(i,a,b)for(int i=b;i>=a;i--)
using namespace std;
const int maxn=2e5+5;
ll n,m;
ll arr[maxn];
ll lcm;
int gcd(int a,int b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
int main(){
    while(~scanf("%lld%lld",&n,&m)){
    rep(i,1,n)
    scanf("%lld",&arr[i]);
    rep(i,1,n){
        if(i==1)lcm=arr[i];
        else lcm=lcm*arr[i]/gcd(lcm,arr[i]);//计算公倍数
    }
    ll sum=0;
    rep(i,1,n)
    sum+=lcm/arr[i];//工人数相加
        if(sum>m||m%sum!=0){//判断是否符合
        printf("No\n");
            continue;}
   else
   {
       printf("Yes\n");
       rep(i,1,n){
           printf("%lld",m/sum*lcm/arr[i]);
           if(i!=n)
               printf(" ");
           else printf("\n");
       }
   }
    }
    return 0;
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值