首页 > 其他分享 >winter week5 day3

winter week5 day3

时间:2024-02-25 21:47:01浏览次数:24  
标签:typedef const winter int double day3 long week5 define

2024牛客寒假算法基础集训营5

A

mutsumi的质数合数

思路:1既不是质数也不是合数

查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e5+5,INF=0x3f3f3f3f,mod=1e9+7,Mod=998244353;
const int MAXN=1e8+5;
const double eps=1e-9;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};

void solve() {
    int n;
    cin>>n;
    int m=n;
    for(int i=0;i<n;++i){
        int x;
        cin>>x;
        if(x==1)m--;
    }
    cout<<m;
}


signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

B

tomorin的字符串迷茫值

C

anon的私货

思路:模拟

对于一个大于1的数x,x减去1则可以在x旁添加1个0,最多添加x-1个,这样x和这些0这一段数的平均值为1;由于添加的0也会影响到原本x旁边的数y,那就取min(x-1,y-1),让x和y都同时减,统计总共减的个数

查看代码
 #include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e5+5,INF=0x3f3f3f3f,mod=1e9+7,Mod=998244353;
const int MAXN=1e8+5;
const double eps=1e-9;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};

void solve() {
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;++i)cin>>a[i];
    int ans=0;
    ans+=a[0]-1;
    for(int i=1;i<n-1;++i){
        int c=min(a[i],a[i+1])-1;
        ans+=c;
        a[i]-=c,a[i+1]-=c;
    }
    if(n!=1)
    ans+=a[n-1]-1;
    cout<<ans;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

E

soyorin的数组操作(easy)

思路:首先偶数肯定是可以的,每次相邻数的差加一,可以操作无限次。其次是奇数,最后一个数是变不了的,那就是看能否让操作次数尽可能少,且倒数第二个数要不大于最后一个数。这里可以考虑倒着处理,由于最后一个数不能变,那就可以由它与前一个数的差值求出前一个数最多能操作多少次,往前同理。最后看序列是否非递减即可

查看代码
 #include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#define double long double
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e6+5,INF=0x3f3f3f3f,mod=1e9+7,Mod=998244353;
const int MAXN=1e8+5;
const double eps=1e-9;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};

void solve() {
    int n;
    cin>>n;
    vector<int>ve(n+1),cnt(n+1);
    for(int i=1;i<=n;++i){
        cin>>ve[i];
    }
    if(n%2==0||n==1)cout<<"YES\n";
    else{
        int k=0;
        for(int i=n-1;i>=1;--i){
            if(i%2==0){
                int now=ve[i]+k*i;
                if(now>ve[i+1]){
                    cout<<"NO\n";
                    return ;
                }
                k+=(ve[i+1]-now)/i;
            }
            ve[i]+=k*i;
            if(ve[i]>ve[i+1]){
                cout<<"NO\n";
                return ;
            }
        }
        cout<<"YES\n";
    }
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
//    init();
    while(t--){
        solve();
    }
    return 0;
}

F

soyorin的数组操作(hard)

这道题很容易被easy影响到。最初想esay的做法时其实就是hard的答案

标签:typedef,const,winter,int,double,day3,long,week5,define
From: https://www.cnblogs.com/bible-/p/18030641

相关文章

  • winter week5 day5
    2024牛客寒假算法基础集训营6A思路:暴力宇宙的终结查看代码#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong//#defineint__int128#definedoublelongdoubletypedefpair<int,int>PII;typedefpair<string,int>PSI;typedefpair<string,stri......
  • day39 动态规划part2 代码随想录算法训练营 63. 不同路径 II
    题目:63.不同路径II我的感悟:题目不难,就是不知道哪个煞笔,把路拦截死了,并且入口就放石头,我真是吐了。理解难点:初始值的遇到障碍要Break其他我写的没错边界考虑:还有入口和出口有障碍物的话,要直接返回0.听课笔记:差不多,考虑的点就是:初始值后面为break开头和结尾有障......
  • day38 动态规划part1 代码随想录算法训练营 746. 使用最小花费爬楼梯
    题目:746.使用最小花费爬楼梯我的感悟:哈哈,我居然自己独立写出来了,确实,只要定义定清楚了,哪怕定的含义只有自己能看懂,只要定义一致就可以求出解决来!!!我真是个大天才!!理解难点:听课笔记:代码示例:classSolution:defminCostClimbingStairs(self,cost:List[int])->int:......
  • day38 动态规划part1 代码随想录算法训练营 70. 爬楼梯
    题目:70.爬楼梯我的感悟:居然自己先写出来了!!继续努力!!理解难点:听课笔记:我的代码:classSolution:defclimbStairs(self,n:int)->int:ifn==1:return1dp=[0]*(n+1)dp[1]=1dp[2]=2foriinran......
  • SDNU_ACM_ICPC_2024_Winter_Practice_1st 赛后
    A:题目给出t个n,对每个n,令n=x+y+z,x|n,y|n,z|n,输出最大的xyz的值。解法打表找规律#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;intmain(){ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);intt;cin>>t;while(t--){......
  • day30 回溯算法总结
     我的感悟:之前一直没看进去,理论篇。今天看了,收获很大。 我的笔记: 资料:卡尔回溯总结卡尔理论视频......
  • winter 2024 第三四周周报
    内容week3day1https://www.cnblogs.com/bible-/p/18018423这天是打寒假牛客2,请假了后面补的题,补了10道吧,感觉这些题花点时间都是可以写的,但是赛时真的很容易被卡,板子题也挺多,线段树、树状数组、字典树(太久不写有点忘了)week3day3https://www.cnblogs.com/bible-/p/18011488打......
  • SMU Winter 2024 div2 ptlks的周报Week 3(2.12-2.18)
    这周主要加强了对知识点的掌握。P10161[DTCPC2024]小方的疑惑10从题目可以得知a个连续括号贡献为a(a+1)/2,代价为2a。要求总贡献恰为k,且代价不高于n。一开始我想到了模拟,先取一个贡献低于k最大的a,剩下的再直接在外面套括号,结果wa。又想到可以分出多个a来组成k,就用递归,每次......
  • winter week3 day1
    2024牛客寒假算法基础集训营2ATokitsukazeandBracelet#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong//#defineint__int128#definedoublelongdoubletypedefpair<int,int>PII;typedefpair<string,int>PSI;typedefpair<stri......
  • day30-三剑客awk
    awk是什么再谈三剑客grep,擅长单纯的查找或匹配文本内容sed,更适合编辑、处理匹配到的文本内容awk,更适合格式化文本内容,对文本进行复杂处理后、更友好的显示三个命令称之为Linux的三剑客awk学完后的能力以下部分内容需要结合shell编程对文本行数据提取数据字段模式、动......