首页 > 其他分享 >hey_left 12 Codeforces Round 859 (Div. 4) 续

hey_left 12 Codeforces Round 859 (Div. 4) 续

时间:2024-01-21 19:59:31浏览次数:27  
标签:12 cout cin int hey 859 solve left

F.

模拟题,不难只是比较繁琐,需要分情况讨论
debug:
如何判断永远走不到终点格?
原思路是这个点同时这个点指向的方向被经过了,那么就是走的重复的路,走不到终点
但不知为何map出了一些问题
后来看题解,只要步数很大了还走不到那么就永远走不到
于是我把map删了,过了

#include <bits/stdc++.h>
using namespace std;

void solve(){
    int n,m;cin>>n>>m;
    int i1,j1,i2,j2;cin>>i1>>j1>>i2>>j2;
    string d;cin>>d;
    int tx=i1,ty=j1;string ts=d;
 //   cout<<"tx="<<tx<<' '<<"ty="<<ty<<'\n';
    int step=0;
    int total=4*n*m+1;
    while(total--) {
        if (tx == i2 && ty == j2) {
            cout << step << '\n';
            return;
        }
        if (ts == "UL") {
            while (1) {
                if (tx == 1 && ty == 1) {
                    ts = "DR";
                    break;
                } else if (tx == 1) {
                    ts = "DL";
                    break;
                } else if (ty == 1) {
                    ts = "UR";
                    break;
                }
                tx--;
                ty--;
//                cout<<"tx="<<tx<<' '<<"ty="<<ty<<'\n';
                if (tx == i2 && ty == j2) {
                    cout << step << '\n';
                    return;
                }
//
            }
        } else if (ts == "UR") {
            while (1) {
                if (tx == 1 && ty == m) {
                    ts = "DL";
                    break;
                } else if (tx == 1) {
                    ts = "DR";
                    break;
                } else if (ty == m) {
                    ts = "UL";
                    break;
                }
                tx--;
                ty++;
                //          cout<<"tx="<<tx<<' '<<"ty="<<ty<<'\n';

                if (tx == i2 && ty == j2) {
                    cout << step << '\n';
                    return;
                }

            }
        } else if (ts == "DL") {
            while (1) {
                if (tx == n && ty == 1) {
                    ts = "UR";
                    break;
                } else if (tx == n) {
                    ts = "UL";
                    break;
                } else if (ty == 1) {
                    ts = "DR";
                    break;
                }
                tx++;
                ty--;
                //         cout<<"tx="<<tx<<' '<<"ty="<<ty<<'\n';

                if (tx == i2 && ty == j2) {
                    cout << step << '\n';
                    return;
                }

            }
        } else if (ts == "DR") {
            while (1) {
                if (tx == n && ty == m) {
                    ts = "UL";
                    break;
                } else if (tx == n) {
                    ts = "UR";
                    break;
                } else if (ty == m) {
                    ts = "DL";
                    break;
                }
                tx++;
                ty++;
                //       cout<<"tx="<<tx<<' '<<"ty="<<ty<<'\n';

                if (tx == i2 && ty == j2) {
                    cout << step << '\n';
                    return;
                }

            }
        }
        step++;
    }
        cout<<"-1"<<'\n';
}

signed main(){
    int hey_left=1;
    cin>>hey_left;
    while(hey_left--){
        solve();
    }
}

G1.

可以把c数组从小到大升序,因为大数只能由比它小的数得到,所以升序不影响
把在a数组里能组成的所有和标记
遍历c数组,若当前数被标记,则满足条件,并把该数加到a数组,更新和
用了dp,从后往前遍历值域

#include <bits/stdc++.h>
using namespace std;

void solve(){
    int n;cin>>n;
    vector<int>c(n+1);
    for(int i=1;i<=n;i++)cin>>c[i];
    sort(c.begin()+1,c.end());
    if(c[1]!=1){
        cout<<"NO"<<'\n';
        return ;
    }
    int dp[5010];
    for(int i=0;i<5010;i++)dp[i]=0;
    dp[1]=1;dp[0]=1;
    for(int i=2;i<=n;i++){
        int t=c[i];
        if(dp[t]){
            for(int j=5000;j>=t;j--){
                if(dp[j-t])dp[j]=1;
            }
        }else{
            cout<<"NO"<<'\n';
            return ;
        }
    }
    cout<<"YES"<<'\n';
}

signed main(){
    int hey_left=1;
    cin>>hey_left;
    while(hey_left--){
        solve();
    }
}

G2.

我服了呀,什么诈骗题,既然是O(n)的还搞什么easy hard
放最后一题我以为很难
像这样的操作方式,可知在前缀和之间的任何数都可以得到,所以排序后直接求前缀和,再遍历判大小即可

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N=2e5+10;

void solve(){
    int n;cin>>n;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a.begin()+1,a.end());
    if(a[1]!=1){
        cout<<"NO"<<'\n';
        return ;
    }
    int sum=1;
    for(int i=2;i<=n;i++){
        if(a[i]>sum){
            cout<<"NO"<<'\n';
            return ;
        }
        sum+=a[i];
    }
    cout<<"YES"<<'\n';
}

signed main(){
    int hey_left=1;
    cin>>hey_left;
    while(hey_left--){
        solve();
    }
}

标签:12,cout,cin,int,hey,859,solve,left
From: https://www.cnblogs.com/wwww-/p/17977965

相关文章

  • Git必知必会基础(12):远程冲突(conflicts)解决--rebase
      本系列汇总,请查看这里:https://www.cnblogs.com/uncleyong/p/10854115.html数据准备重新克隆  日志 远程分支qzcsbj.txt内容 commitid 其他人提交模拟其他人对master做了提交:直接gitee上修改文件并提交 新的commitid 本地提交本地分支修改q......
  • 1.21寒假每日总结12
    思路&&Code12345678910111213141516171819202122232425262728293031323334353637/*高桥和青木N场比赛x      y得分情况分别为x1y1              ...                ..  ......
  • 20230120
    A.真实排名分类当前选手是否被操作,组合#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong#defineullunsignedlonglong#defineALL(a)(a).begin(),(a).end()#definepbpush_back#definemkmake_pair#definepiipair<int,int>#definepisp......
  • hey_left 11 Codeforces Round 859 (Div. 4)
    题目链接A.直接判断输出#include<bits/stdc++.h>usingnamespacestd;voidsolve(){inta,b,c;cin>>a>>b>>c;if(a+b==c)cout<<'+'<<'\n';elseif(a-b==c)cout<<"-"<<'\n&#......
  • STM32CubeMX教程20 SPI - W25Q128驱动
    1、准备材料开发板(正点原子stm32f407探索者开发板V2.4)STM32CubeMX软件(Version6.10.0)野火DAP仿真器keilµVision5IDE(MDK-Arm)ST-LINK/V2驱动XCOMV2.6串口助手逻辑分析仪nanoDLA2、实验目标使用STM32CubeMX软件配置STM32F407开发板的SPI1与W25Q128芯片通信,以轮询方式读......
  • 寒假生活指导12
    importurllib.requesturl='https://dianying.taobao.com/cityAction.json?activityId&_ksTS=1629789477003_137&jsoncallback=jsonp138&action=cityAction&n_s=new&event_submit_doGetAllRegion=true'headers={#':authori......
  • CF1712A
    看完题目,很容易得知要使$\sum\limits_{i=1}^kp_i$最小,且\(p_i\)是\(n\)的一个排列,可以知道最终的答案为\(\sum\limits_{i=1}^ki\)。现在我们考虑如何将原序列转化成答案序列。得知答案后,我们要做的就是将所有的\(p_i\lek\)移到序列的前\(k\)位中。暴力枚举序列的......
  • P8112 [Cnoi2021] 符文破译 题解
    题目传送门思路先看数据范围,我们发现两个字符串的长度最大会达到\(5\times10^7\)。这立刻打消了我用暴力的想法。于是,我选择了用KMP模式匹配,这一个能够在线性时间内判定字符串\(A\)是否是字符串\(B\)的字串,并求出字符串\(A\)在字符串\(B\)中各次出现的位置。如......
  • CF1612G Max Sum Array
    MaxSumArrayLuoguCF1612G题面描述给定一个长为\(m\)的序列\(c_1,c_2,\dots,c_m\)。序列\(A\)满足:对于所有\(1\leqi\leqm\),\(i\)在\(A\)中出现了\(c_i\)次。定义一个序列\(A\)的值如下:\[f(A)=\sum_{1\leqi<j\leqn,a_i=a_j}j-i\]求满足条件的\(f......
  • hey_left 10 Codeforces Round 871 (Div. 4) 再续
    题目链接H.没思路,查看题解选择数组的非连续的子序列,就是每个数选或不选的问题求个数,易dp求子序列的数二进制相与结果有k个1的个数把所有结果记录,再去筛选满足条件的结果f[i][j]表示到第i个数,相与结果为j的子序列个数正向思维:多个数相与得到结果dp思维:枚举结果,考虑数如何......