河西-8.8上午3教室-廖

· · 个人记录

T1

错误原因:如果是炮,少判断是否在同一列

题意:车 1 可沿横线或者竖线移动,即一次操作可以吃掉 (x+k,y),(x−k,y),(x,y+k),(x,y−k) 中的任意一个位置的棋子(k 为任意正整数)。

炮 2 想象一条直线,炮与对方棋子都在这条直线上。那么只有在这条直线上的炮与对方棋子的中间有一个另外的棋子时,炮才能吃掉对方。

马 3 马走日,即一次操作可以吃掉 (x+2,y+1),(x+2,y−1),(x−2,y+1),(x−2,y−1),(x+1,y+2),(x+1,y−2),(x−1,y+2),(x−1,y−2) 中的任意一个位置的棋子。

象 4 象走田,即一次操作可以吃掉 (x+2,y+2),(x+2,y−2),(x−2,y+2),(x−2,y−2) 中的任何一个位置的棋子。

题解

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long p,x0,y0,x1,y1;
    cin>>p>>x0>>y0>>x1>>y1;
    if(p==1)
    {
        if(x0==x1||y0==y1)cout<<"Yes";
        else cout<<"No";
    }
    else if(p==2)
    {
        if(abs(y0-y1)>1&&y0==y1)cout<<"Yes";
        else cout<<"No"; 
    }
    else if(p==3)
    {
        if(abs(x0-x1)==1&&y0!=y1)cout<<"Yes";
        else cout<<"No";
    }
    if(p==4)
    {
        if(abs(x0-x1)==2&&abs(y0-y1)==2)cout<<"Yes";
        else cout<<"No";
    } 
    return 0;   
} 

T2

错误原因:超时

题意:给定一个正整数 n,设 n=p 1×p 2×…p k ,其中 p i均为质数,对 1≤i<k,p i ≤pi+1。可以证明,序列 p i是唯一的。对每个给定的 n,请你求出 p 1,p 2,…p k。

题解

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll x;
        cin>>x;
        for(ll i=2;i*i<=x;i++)//枚举质因子
        {
            while(x%i==0)//一旦找到一个因子,反复除该因子
            {
                cout<<i<<" ";//输出该因子
                x/=i;//缩小现在的数字
            }
        } 
        if(x!=1)//如果存在最后分解完的数字为一个质数,那么输出它
        {
            cout<<x<<" ";
        } 
        cout<<endl;
    } 
    return 0;
}

T4

错误原因:没看题

题意:有k个地方可能有炸弹,炸弹在哪里威胁到的区域更多?

题解

#include<bits/stdc++.h>
#define ll long long
using namespace std;
double jl(int a,int b,int c,int d)
{
    return sqrt((a-c)*(a-c)+(b-d)*(b-d));
} 
int main()
{
    int n,m,k,t;
    cin>>n>>m>>k>>t;
    int maxx=INT_MIN;
    while(k--)
    {
        int x,y;
        cin>>x>>y;
        int cnt=0;
        for(int i=max(1,x-t);i<=min(n,x+t);i++)
        {
            for(int j=max(1,y-t);j<=min(m,y+t);j++)
            {
                if( jl(x,y,i,j) <= t)
                {
                    cnt++;
                }
            }
        } 
        maxx=max(maxx,cnt);
    } 
    cout<<maxx;
    return 0;
}

T5

错误原因:细节错误太多50分

题意:只能由 a∼z 之间 26 个小写字母、A∼Z 之间 26 个大写字母、0∼9 之间 10 个数字以及 !@#$ 四个特殊字符构成。

密码最短长度 :6 个字符,密码最大长度 :12 个字符。

大写字母,小写字母和数字必须至少有其中两种,以及至少有四个特殊字符中的一个。

满足以上要求的就输出

题解

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    char x;
    string tmp="";//当前的单词
    int cnt1=0;//小写字母是否出现过
    int cnt2=0;//大写字母是否出现过
    int cnt3=0;//数字是否出现过
    int cnt4=0;//特殊符号是否出现过
    int cnt5=0;//其他符号是否出现过
    int cnt6=0;//当前长度
    while(cin>>x)
    {
        if(x!=',')
        {
            tmp+=x;//拼接
            if(x>='a'&&x<='z')
            {
                cnt1=1;
            } 
            else if(x>='A'&&x<='Z')
            {
                cnt2=1;
            } 
            else if(x>='0'&&x<='9')
            {
                cnt3=1;
            } 
            else if(x=='!'||x=='@'||x=='#'||x=='$')
            {
                cnt4=1;
            } 
            else
            {
                cnt5=1;
            } 
            cnt6++;
        } 
        else
        {
            if(cnt1+cnt2+cnt3>=2&&cnt4==1&&cnt5==0&&cnt6>=6&&cnt6<=12)
            {
                cout<<tmp<<endl;
            } 
            tmp="";
            cnt1=cnt2=cnt3=cnt4=cnt5=cnt6=0;
        }
    } 
    if(cnt1+cnt2+cnt3>=2&&cnt4==1&&cnt5==0&&cnt6>=6&&cnt6<=12)
    {
        cout<<tmp<<endl;
    }
    return 0;
}