2020/5/17牛客小白月赛25

 

A.AOE还是单体?

https://ac.nowcoder.com/acm/contest/5600/A

      题意:牛可乐准备和 n个怪物厮杀,有i个怪物血量分别为a[i],牛可乐有两种技能

                1.蛮牛冲撞,消耗1mp  ,可以对任意单体怪物造成 1点伤害。
                2.蛮牛践踏,消耗 xmp,可以对全体怪物造成 1点伤害。
                  求将这些怪物全部击杀后,消耗的最小mp
                如果消耗xmp,对怪物造成的总伤害大于x,则用技能2划算,反之用第一种划算
                根据怪物血量对怪物排序,x>n时直接用技能一,x<=n时先用技能二杀掉前x-n个怪物,在用技能一 
View Code

 

E.点击消除

https://ac.nowcoder.com/acm/contest/5600/E

   题意:给一个字符串,如果两个字母相邻,则可以消除这两个字母,不限消除次数,最后字符数为零则输出0,

              反之输出最后的字符串。

 

 1. 比赛的时候对,赛后再试超时的代码

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
 
int main(){
    string s;
    cin>>s;
    int len=s.length();
    while(1){
        int flag=0;
        for(int i=0;i<len;i++){
            if(s[i]==s[i+1]){
                s.erase(i,2);
                len=len-2;
                flag=1;
               }
        }
        if(flag==0){
            break;
        }
         
    }
    if(len<=0){
        cout<<"0"<<endl;
    }else{
         cout<<s<<endl;
    }
      
      return 0;
}
View Code

 2.用栈   #include<stack>

     栈(stack)是后进先出的数据结构只能通过top()来访问栈顶元素,常用函数

      push()入栈  top()获得栈顶元素 pop()弹出栈顶元素 empty()检查栈内是否为空 size()栈内元素个数

   

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<stack>
using namespace std;
int main(){
    string s;
    cin>>s;
    stack<char>c;
    int len=s.length();
    for(int i=len-1;i>=0;i--){
        if(c.empty()||s[i]!=c.top()){
            c.push(s[i]);
        }else if(s[i]==c.top()){
            c.pop();
        }
    }
    if(c.empty()){
        cout<<"0"<<endl;
    }else{
        while(!c.empty()){
            cout<<c.top();
            c.pop();
        }
    }
    return 0;
} 
View Code

G.解方程

https://ac.nowcoder.com/acm/contest/5600/G

           求解方程xa+blnx=c

          1.牛顿迭代法

                    

 

 

 

#include<cstdio>
#include<iostream> 
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    double x=1;
    while(fabs(pow(x,a)+b*log(x)-c)>0.0000001){    
        x=x-(pow(x,a)+b*log(x)-c)/(a*pow(x,a-1)+b/x);
    }
     printf("%.14lf",x);
     return 0;
}
View Code

      2.二分法

#include<cstdio>
#include<cmath> 
#include<iostream>
using namespace std;
typedef long long ll;
const double eps = 1e-8;
double a,b,c;
bool check(double x){
     
     return pow(x,a)+b*(log(x))>=c;
}
int main(){
    cin>>a>>b>>c;
    double l=0,r=1e9,mid=0,res=0;
    while(r-l>eps){
        mid=(l+r)/2;
        if(mid-l<eps){
            res=l;
            break;
        }
        if(check(mid)){
            r=mid;
        }else{
            l=mid;
        }
    }
     printf("%.10f\n",res);
     return 0;
}
View Code

 

F.疯狂的自我检索者

https://ac.nowcoder.com/acm/contest/5600/F

       题解:假设所有隐藏的分数为1或5

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int a[200010];
int main(){
    double n,m;
    double max=0,min=0;
    long long sum=0;
    cin>>n>>m;
    for(int i=1;i<=n-m;i++){
        cin>>a[i];
        sum+=a[i];
    }
    max=(sum+m*5)/n;
    min=(sum+m)/n;
    printf("%.5f %.5f\n",min,max);
    return 0;
}
View Code

H.神奇的字母(二)

https://ac.nowcoder.com/acm/contest/5600/H

    题意:输出出现次数最多的字母

                  对“若干组输入”的处理方式。(从别人那看到的)
                  1.while(cin>>str)
                  2.while(scanf("%s",str)!=EOF) 
                  3.while(gets(str)!=NULL)

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
int a[30];
int main(){
       char ch;
       char s[1002],c;
       int max=-1,flag;
       while(gets(s)!=NULL){
           int len=strlen(s);
           int max=-1,flag;
           for(int i=0;i<len;i++){
            if(s[i]>='a'&&s[i]<='z'){
                a[s[i]-'a'+1]++;
               }
            }              
       }
         
   for(int i=1;i<=26;i++){
         if(a[i]>max){
            max=a[i];
            flag=i;
         }
    }
    c=flag+'a'-1;
    cout<<c<<endl;
    return 0;
     
}
View Code

I.十字爆破

 题意:求每个格子处的得分情况,即该各自所在行列之和再减其本身

https://ac.nowcoder.com/acm/contest/5600/I

#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main(){
     int n,m,i,j;
     scanf("%d%d",&n,&m);
     long long a[n][m];
     long long hang[n],lie[m];
     memset(hang,0,sizeof(hang));
     memset(lie,0,sizeof(lie));
     for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%lld",&a[i][j]);
            hang[i]+=a[i][j];
         }
     }
         
     for(i=0;i<m;i++){
        for(j=0;j<n;j++){
            lie[i]+=a[j][i];
         }
     }
     for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            a[i][j]=hang[i]+lie[j]-a[i][j];
            printf("%lld",a[i][j]);
            if(j!=m-1) printf(" ");
         }
         printf("\n");
     }
     return 0;
}
View Code

 

posted @ 2020-05-23 22:37  Endeavo_r  阅读(226)  评论(0)    收藏  举报