Codeforces Round #188 (Div. 2)

来源:互联网 发布:知乎为什么不能提问? 编辑:程序博客网 时间:2024/06/05 17:30

很长时间没有做了,也就很长时间没有写了,rating哗哗的往下掉啊 ,已经变绿了,这次三题挂了一个,a2Y,b1Y,

A

#include <iostream>#include<cstring>#include<cstdio>using namespace std;int main(){    long long  i,j,k,n,m;    cin>>n>>k;    m = k*2-1;    if(m>n)    {        long long x = (n+1)/2;        cout<<(k-x)*2<<endl;    }    else    cout<<m<<endl;    return 0;}

B

#include <iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<stdlib.h>using namespace std;char str[1000010];int main(){    int i,j,k,n,num=0;    char s1[20],s2[20];    long long s=0;    cin>>str;    k = strlen(str);    for(i = 0 ; i < k ; i++)    {        if(i+5>k)        break;        if(str[i]=='h'&&i+5<=k)        {            int g=0;            for(j = i ; j < i+5 ; j++)            s1[g++] = str[j];            s1[g] = '\0';            if(strcmp(s1,"heavy")==0)            {                num++;                i+=4;            }        }        if(str[i]=='m'&&i+5<=k)        {            int g= 0;            for(j = i ; j < i+5 ; j++)            s2[g++] = str[j];            s2[g] = '\0';            if(strcmp("metal",s2)==0)            {                s+=num;                i+=4;            }        }    }    cout<<s<<endl;    return 0;}

C 之后稍改了下 就A了

#include <iostream>#include<cstring>#include<algorithm>#include<stdlib.h>using namespace std;int main(){    int i,j,k;    long long a,b,m,t,g=0;    cin>>a>>b>>m;    if(a>=m||b>=m)    {        cout<<"0\n";        return 0;    }    if(a<b)    {        t = a;        a = b;        b = t;    }    if(a>0&&b<0)    {        g = -b/a;        b = g*a+b;    }    long long s = a+b;    long long s1 = s;    long long num=1;    while(s<m)    {        long long k = max(a,b);        a = k;        b = s;        s = a+b;        num++;        if(s<=s1)        {            cout<<"-1\n";            return 0;        }    }    cout<<g+num<<endl;    return 0;}


原创粉丝点击