The 2024 Sichuan Provincial Collegiate Programming Contest补题

B连接召唤

#include<iostream>
#include<algorithm>
using namespace std;
#define int long long
void solve()
{
    int ans=0;
    int a[7];
    for(int i=1;i<=5;i++)
        cin>>a[i];

    int temp=0;
    
    temp=a[3]/2;
    ans+=temp;
    a[3]-=temp*2;

    temp=min(a[4],a[2]);
    ans+=temp;
    a[4]-=temp;a[2]-=temp;

    temp=min(a[5],a[1]);
    ans+=temp;
    a[5]-=temp;a[1]-=temp;
    if(a[5]){
        temp=min(a[5],a[2]);
        ans+=temp;
        a[5]-=temp;a[2]-=temp;

        if(a[5]){
            temp=min(a[5],a[3]);
            ans+=temp;
            a[5]-=temp;a[3]-=temp;

            if(a[5]){
                temp=min(a[5],a[4]);
                ans+=temp;
                a[5]-=temp;a[4]-=temp;

                if(a[5]){
                    temp=a[5]/2;
                    ans+=temp;
                    a[5]-=temp*2;
                }
            }
        }
    }

    temp=min(a[1]/2,a[4]);
    ans+=temp;
    a[4]-=temp;a[1]-=temp*2;

    if(a[4]){
        a[2]+=a[1];a[1]=0;
        temp=(a[2]/2,a[4]);
        ans+=temp;
        a[2]-=temp*2;a[4]-=temp;

        if(a[4]){
            a[3]+=a[2];a[2]=0;
            temp=(a[3]/2,a[4]);
            ans+=temp;
            a[3]-=temp*2;a[4]-=temp;

            if(a[4]){
                a[4]+=a[3];a[3]=0;
                temp=a[4]/3;
                ans+=temp;
                a[4]-=temp*3;
            }
        }
    }

    temp=min(a[3],min(a[2],a[1]));
    ans+=temp;
    a[3]-=temp;a[2]-=temp;a[1]-=temp;

    if(a[3]&&a[2]){
        temp=min(a[2]/2,a[3]);
        ans+=temp;
        a[2]-=temp*2;a[3]-=temp;
    }
    ans+=(a[1]+2*a[2]+3*a[3])/6;
    cout<<ans<<endl;
}

signed main()
{
    int T;
    cin>>T;
    while(T--)
        solve();
    return 0;
}

E L型覆盖检查器

#include<iostream>
#include<string>
#include<vector>
using namespace std;

void solve()
{
    int n,m;
    cin>>n>>m;
    string temp(m+2,'K');
    vector<string> a(n+2,temp);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        a[i]='K'+a[i]+'K';
    }
    if(n*m%3!=1){
        cout<<"No\n";
        return;
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            if(i==1&&j==m){
                if(a[i][j]!='.'){
                    cout<<"No\n";
                    return;
                }
                else
                    continue;
            }
            switch (a[i][j]){
                case '.' :
                    cout<<"No\n";
                    return;
                    break;
                case 'L' :
                    if(a[i][j-1]!='C'){
                        cout<<"No\n";
                        return;
                    }
                    break;
                case 'R' :
                    if(a[i][j+1]!='C'){
                        cout<<"No\n";
                        return;
                    }
                    break;
                case 'U' :
                    if(a[i-1][j]!='C'){
                        cout<<"No\n";
                        return;
                    }
                    break;
                case 'D' :
                    if(a[i+1][j]!='C'){
                        cout<<"No\n";
                        return;
                    }
                    break;
                case 'C':
                    if( (a[i][j+1]=='L'&&a[i+1][j]=='U')||
                        (a[i][j+1]=='L'&&a[i-1][j]=='D')||
                        (a[i][j-1]=='R'&&a[i+1][j]=='U')||
                        (a[i][j-1]=='R'&&a[i-1][j]=='D')
                    ){
                        continue;
                    }
                    else{
                        cout<<"No\n";
                        return;
                    }
                    break;
            }
        }
    cout<<"Yes\n";
    return;
}

int main()
{
    int T;
    cin>>T;
    while(T--)
        solve();
    return 0;
}

F 小球进洞:平面板

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define int long long


const double eps =1e-8;
const double PI=acos(-1.0);

int sgn(double x)
{
    //平行 
    if(fabs(x)<eps)
        return 0;
    //相交方向
    if(x<0)
        return -1;
    else
        return 1;
}


struct Point
{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x=_x;y=_y;
    }
    Point operator -(const Point &b)const{
        return Point(x-b.x,y-b.y);
    }
    double operator ^(const Point &b)const{
        return x*b.y-y*b.x;
    }
    double operator *(const Point &b)const{
        return x*b.x+y*b.y;
    }

    
};

struct Line
{
    Point s,e;
    Line(){}
    Line(Point _s,Point _e){
        s=_s;e=_e;
    }
};

bool inter(Line l1,Line l2)
{
    return
    max(l1.s.x,l1.e.x) >= min(l2.s.x,l2.e.x) &&
    max(l2.s.x,l2.e.x) >= min(l1.s.x,l1.e.x) &&
    max(l1.s.y,l1.e.y) >= min(l2.s.y,l2.e.y) &&
    max(l2.s.y,l2.e.y) >= min(l1.s.y,l1.e.y) &&
    sgn((l2.s-l1.e)^(l1.s-l1.e))*sgn((l2.e-l1.e)^(l1.s-l1.e)) <= 0 &&
    sgn((l1.s-l2.e)^(l2.s-l2.e))*sgn((l1.e-l2.e)^(l2.s-l2.e)) <=0 ;
}

void solve()
{
    int x,y,r,vx,vy,x1,y1,x2,y2;
    cin>>x>>y>>r>>vx>>vy>>x1>>y1>>x2>>y2;
    int temp=2e6/max(fabs(vx),fabs(vy));
    Point s(x,y),e(x+temp*vx,y+temp*vy);
    Line run(s,e);
    x1+=r;y1+=r;x2-=r;y2-=r;

    if(x1>x2||y1>y2){
        cout<<"No\n";
        return;
    }

    Point a1(x1,y2),a2(x2,y2),a3(x1,y1),a4(x2,y1);
    Line l1(a1,a2),l2(a1,a3),l3(a3,a4),l4(a2,a4);

    if(inter(run,l1)||inter(run,l2)||inter(run,l3)||inter(run,l4))
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return;
}

signed main()
{
    int T;
    cin>>T;
    while(T--)
        solve();
    return 0;
}

H GG和YY的石子游戏

#include<iostream>
using namespace std;
#define int long long
#define endl '\n'
void solve()
{
    int n;
    cin>>n;
    if(n%3==0)
        cout<<1<<' '<<n/3<<endl;
    else
        cout<<0<<' '<<n/3+n%3<<endl;
    return;
}

signed main()
{
    int T;
    cin>>T;
    while(T--)
        solve();
    return 0;
}

I 集装箱调度

#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
struct tangle{
    int x1,y1,x2,y2;
    tangle(){}
    tangle(int _x1,int _y1,int _x2,int _y2){
        x1=_x1;y1=_y1;x2=_x2;y2=_y2;
    }
};

struct point{
    int x,y;
    point(){}
    point(int _x,int _y){
        x=_x;y=_y;
    }
};

/*
假设两矩形的宽高分别是 w1,h1,w2,h2。

分别计算两个矩形的中心点 O1,O2,以及 O1 和 O2 之间的水平距离(w)和竖直距离(h)。

若2* w < w1 + w2  且 2* h <  h1 + h2 ,则两个矩形相交,否则不相交。
*/
bool check_tangle(tangle a,tangle b)//相交返回true
{
    return fabs(a.x1+a.x2-b.x1-b.x2) < a.x2-a.x1+b.x2-b.x1 
        && fabs(a.y1+a.y2-b.y1-b.y2) < a.y2-a.y1+b.y2-b.y1;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,l,h;
    cin>>n>>l>>h;
    //被激活的坐标
    vector<int> px,py;
    px.push_back(0);
    py.push_back(0);
    //已经存放了的矩形
    vector<tangle> b;
    for(int i=1,_l,_h;i<=n;i++){
        cin>>_l>>_h;
        bool flag=false;
        tangle temp;
        point P;
        for(int j=0;j<px.size()&&!flag;j++)
            for(int q=0;q<py.size()&&!flag;q++){
                //挑选第P个点
                P.x=px[j];P.y=py[q];
                if(P.x+_l>l||P.y+_h>h)
                    continue;
                bool check=true;
                //想要构成的新矩形
                temp=tangle(P.x,P.y,P.x+_l,P.y+_h);
                for(int k=0;k<(int)b.size()&&check;k++){//检查点P添加不会影响之前的矩形
                    if(check_tangle(temp,b[k])){//两个矩形相交
                        check=false;
                        break;
                    }
                }
                if(check==true)
                    flag=true;
            }

        if(!flag){
            cout<<-1<<endl;
        }
        else{
            cout<<P.x<<' '<<P.y<<endl;
            //放入新的矩形
            b.push_back(temp);
            px.push_back(temp.x2);
            py.push_back(temp.y2);
            sort(px.begin(),px.end());
            sort(py.begin(),py.end());
        }
    }
    return 0;
}

L 毛肚下清汤?

#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;

#define pii pair<int,int>
#define mk make_pair
#define int long long

struct cmp{
    bool operator()(pii &a,pii &b){
        return a.second>b.second;
    }
};

signed main()
{
    int n;
    cin>>n;
    priority_queue<pii,vector<pii>,cmp> q1,q2;
    for(int i=1,x,y,a,b;i<=n;i++){
        cin>>x>>y>>a>>b;
        if(a==1&&b==1){
            if(x<y)
                q1.push(mk(i,x));
            else
                q2.push(mk(i,y));
        }
        else if(a==0)
            q2.push(mk(i,y));
        else
            q1.push(mk(i,x));
    }   
    cout<<q1.size()<<' ';
    while(!q1.empty()){
        int temp=q1.top().first;
        cout<<temp<<' ';
        q1.pop();
    }
    cout<<'\n';
    cout<<q2.size()<<' ';
    while(!q2.empty()){
        int temp=q2.top().first;
        cout<<temp<<' ';
        q2.pop();
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值