z第二次练习课

· · 科技·工程

1.三国杀

这道题就是要理清思路,被淘汰只有两种办法 1.杀比斩多,2.斩比杀多 所以进行简单的判断就行

#include<bits/stdc++.h>
using namespace std;
int c1,c2,c3,d1,d2,d3;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {//小c只输出就行
        cin>>c1>>c2>>c3>>d1>>d2>>d3;
        if(c1>d2||c3>d1)
        {
            cout<<"C"<<endl;
        }
        else if(d1-c3>c2||d3>c1)//保证D杀被消耗后,杀比C斩多
        {
            cout<<"D"<<endl;
        }
        else 
        {
            cout<<"E"<<endl; 
        } 
    }

    return 0;   
} 

2.男生女生

这道题只用针对2种情况,给出两种方法就行 1。男多女少 男女男.... 2.女多男少 女男女....

#include<bits/stdc++.h>
using namespace std;
int n,m;

int main()
{
    cin>>n>>m;

    while(n+m!=0)
    {
        if(n>m)男比女多
        {
            if(n!=0)
            {
                cout<<"B"; 
                n--;
            }
            if(m!=0)
            {
                cout<<"G"; 
                m--;
            }
        }
        else//女比男多
        {

            if(m!=0)
            {
                cout<<"G"; 
                m--;
            }   
            if(n!=0)
            {
                cout<<"B"; 
                n--;
            }

        }

    }

    return 0;   
} 

3.电脑耗电计算

这道题跟我们数学题中的分段计费差不多,所以思路也大差不差 针对不同的模式做不同的模拟

#include<bits/stdc++.h>
using namespace std;
int n,p1,p2,p3,t1,t2;
int r[105],l[105];
int main()
{
    cin>>n>>p1>>p2>>p3>>t1>>t2;
    for(int i=1;i<=n;i++)
    {
        cin>>l[i]>>r[i];
l是开始,r是结束
    }
    int sum=0;//总消耗
    for(int i=1;i<=n;i++)
    {
        int tmp=l[i]-r[i-1];
        //开始减结束时间 
        if(i==1)//特判
        {
            tmp=0;
        }

        if(tmp<=t1)//未达到屏保时间,正常消耗
        {
            sum+=tmp*p1;
        }
        else if(tmp<=t1+t2)
//达到了屏保时间,但未达到休眠之前
        {
            sum+=t1*p1+(tmp-t1)*p2;
        }
        else//达到屏保时间休眠
        {
            sum+=t1*p1+t2*p2+(tmp-t1-t2)*p3; 
        }
//所以的操作累加
        sum+=(r[i]-l[i])*p1;
    }
    cout<<sum;
    return 0;   
}