首页 > 其他分享 >Namomo Winter Camp 2023 Day 2

Namomo Winter Camp 2023 Day 2

时间:2023-01-11 14:33:09浏览次数:35  
标签:std ch int res Camp long 2023 Day getchar

A - Mix Juice

排个序再求和就好

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

int read(){...}

int32_t main(){
    int n = read() , k = read();
    vector<int> a(n);
    for( auto & i : a ) i = read();
    sort( a.begin() , a.end() );
    int res = 0;
    for( int i = 0 ; i < k ; i ++ ) res += a[i];
    cout << res << "\n";

    return 0;
}

B - One Quadrillion and One Dalmatians

进制转换,因为没有0所以要特殊处理一下

#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;

int32_t main(){
    int n; cin >> n;
    vector<int>res;
    do{
        n-- , res.push_back( n%26 ) , n /= 26;
    }while( n > 0 );
    std::reverse(res.begin(), res.end());
    for( int i : res )
        cout << char(i+'a');
}

C - Replacing

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

int read(){
    int x = 0 , f = 1 , ch = getchar();
    while( (ch < '0' || ch > '9') && ch != '-' ) ch = getchar();
    if( ch == '-' ) f = -1 , ch = getchar();
    while( ch >= '0' && ch <= '9' ) x = ( x << 3 ) + ( x << 1 ) + ch - '0' , ch = getchar();
    return x * f;
}

const int N = 1e5+5;
int v[N] , res = 0;

int32_t main(){
    for( int n = read() , x ; n ; n -- ) x = read() , res += x , v[x] ++;
    for( int q = read() , b , c ; q ; q -- )
        b = read() , c = read() , res += (c-b) * v[b] , v[c] += v[b] , v[b] = 0 , printf("%lld\n" , res );
    return 0;
}

D - Red Scarf

因为保证了偶数,所以把所有的数异或起来就等于原数每个数异或起来。然后再异或剩余的数就是原数

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

int read(){
    int x = 0 , f = 1 , ch = getchar();
    while( (ch < '0' || ch > '9') && ch != '-' ) ch = getchar();
    if( ch == '-' ) f = -1 , ch = getchar();
    while( ch >= '0' && ch <= '9' ) x = ( x << 3 ) + ( x << 1 ) + ch - '0' , ch = getchar();
    return x * f;
}

int32_t main(){
    int n = read() , sum = 0;
    vector<int> a(n);
    for( auto & i : a ) i = read() , sum ^= i;
    for( auto i : a ) printf("%lld " , sum ^ i );
    return 0;
}

F - Minor Change

#include<bits/stdc++.h>
#define int unsigned long long
typedef long long ll;
using namespace std;

int32_t main(){
    ios::sync_with_stdio(false) , cin.tie();
    string s , t;
    int res = 0;
    cin >> s >> t;
    for( int i = 0 ; i < s.size() ; i ++ )
        if( s[i] != t[i] ) res ++;
    cout << res << "\n";
    return 0;
}

G - Tsundoku

排序,求前缀和,枚举一个买多少二分另一个能买多少,然后判断一下就好

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

int read(){
    int x = 0 , f = 1 , ch = getchar();
    while( (ch < '0' || ch > '9') && ch != '-' ) ch = getchar();
    if( ch == '-' ) f = -1 , ch = getchar();
    while( ch >= '0' && ch <= '9' ) x = ( x << 3 ) + ( x << 1 ) + ch - '0' , ch = getchar();
    return x * f;
}

int32_t main(){
    int n = read() , m = read() , k = read() , res = 0;
    vector<int> a(n+1) , b(m+1);
    for( int i = 1 ; i <= n ; i ++ ) a[i] = read();
    for( int i = 1 ; i <= m ; i ++ ) b[i] = read();
    for( int i = 1 ; i <= n ; i ++ ) a[i] += a[i-1];
    for( int i = 1 ; i <= m ; i ++ ) b[i] += b[i-1];
    for( int i = 0 , t , j ; i <= n ; i ++ ){
        if( a[i] > k ) break;
        t = k - a[i];
        j = upper_bound( b.begin() , b.end() , t ) - b.begin() - 1;
        res = max( res , i + j );
    }
    cout << res << "\n";
}

H - Sum of Divisors

做一个类似埃筛的东西,去标记一个数的倍数,这样可以\(O(n\log n)\)的求出所有数有多少个因子,然后再\(O(n)\)的算一边就好

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


int32_t main(){
    int n;
    cin >> n;
    vector<int> f(n+1);
    for( int i = 1 ; i <= n ; i ++ )
        for( int j = i ; j <= n ; j += i ) f[j]++;
    int res = 0;
    for( int i = 1 ; i <= n ; i ++ ) res += i * f[i];
    cout << res << "\n";
    return 0;
}

I - NEQ(补题)

首先这题赛时没出就是自己傻逼了,预处理阶乘的是否忘记取模

首先我们不考虑\(B_i\),只考虑\(A_i\)的情况,显然有\(A_m^n\)中情况,然后我们要计算出对于每一个序列\(A\)有多少个序列\(B\),易知对于每种序列\(A\)符合条件的序列\(B\)的数量是相等的。

直接计算合法的序列\(B\)比较困难,我们用序列\(B\)的总数减去不合法的数量就是合法的数量。

用到了一个组合容斥,暂时还不太会,后面补一下。

\[cnt=\sum_{k=0}^n (-1)^k\times C(n,k) \times A(m-k,n-k) \]

最后的答案就是\(cnt\times A(m,n)\)

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

const int N = 5e5+5 , mod = 1e9+7;
int fact[N] , invFact[N] , n , m , res = 0;

int power(int x,int y)
{
    int ans =1;
    while(y)
    {
        if( y & 1 ) ans = ans * x % mod;
        x= x * x %mod;
        y>>=1;
    }
    return ans;
}

int inv( int x ){
    return power( x , mod - 2 );
}

int A( int x , int y ){
    return fact[x] * invFact[x-y] % mod;
}

int C( int x , int y ){
    return fact[x] * invFact[x-y] % mod * invFact[y] % mod;
}

int32_t main(){
    fact[0] = 1 , invFact[0] = inv(1);
    for( int i = 1 ; i < N ; i ++ ) fact[i] = fact[i-1] * i % mod , invFact[i] = inv(fact[i]);
    cin >> n >> m;
    for(int i = 0;i <= n;i++){
        if(i&1) res=(res-C(n,i)*A(m-i,n-i)%mod+mod)%mod;
        else res=(res+C(n,i)*A(m-i,n-i)%mod)%mod;
    }
    cout << res * A(m,n) % mod;
}

标签:std,ch,int,res,Camp,long,2023,Day,getchar
From: https://www.cnblogs.com/PHarr/p/17043656.html

相关文章

  • 2023-01-11 小程序 Empty file is NOT a valid json file
    问题描述:wepy小程序预览时报错,说我的一个json文件是空文件,就是没代码,空的。原因:不详,我估计是微信开发者工具的问题。解决方案:删掉dist包,重新npmrunbuild打包,然后在微信......
  • 【2023-01-04】父母使命
    20:00白的米饭、甜的果子是平凡的,然能适合大多数人的胃口,所以是最好的食物,艺术也是一样。                        ......
  • 【2023-01-03】除旧迎新
    20:00多美好的一天呵!花园里干活儿,晨雾已消散,蜂鸟飞上忍冬的花瓣。世界上没有任何东西我想占为己有,也没有任何人值得我深深抱怨;那身受的种种不幸我早已忘却,依然故我的思想......
  • Day01
    知识点梳理C#特性[]反射理解,C++实现反射C#使用,API泛型单例,MonoSingletonOdin插件安装与使用*对象池C#拓展方法C#自定义特性反射单例Odin插件对象池......
  • 【2023.01.10】PVE7.3安装黑群晖7.x
    资源网站:Releases·fbelavenuto/arpl(github.com)下载Releases·fbelavenuto/arpl(github.com)使用PVE的话下载img.zip文件就可以解压出文件,然后上传到PVE里头......
  • day1---二分查找打卡---力扣704--力扣27
     打卡第一天,希望自己可以坚持两个月,把算法能力提升去,然后方便找工作。然后很久没有刷算法题目了,这次的态度要很端正,因为之前刷题目的过程都不是一个非常完整的过程,所以......
  • 算法刷题 Day 14 | 二叉树的递归遍历
    今日内容:理论基础递归遍历迭代遍历统一迭代详细布置理论基础需要了解二叉树的种类,存储方式,遍历方式以及二叉树的定义文章讲解:https://programm......
  • 【记录】自我批判ver2023-1-10
    1.你认为的社会是怎么样的,那么,你对社会的这个怎么样是促进了还是阻碍了。如果你认为社会是险恶的,那么,你是增进了社会的险恶还是让社会不再更加险恶?如果你认为社会是美好......
  • 2023.1.10交换两个变量值的函数
    ......
  • 2023.1.10判断是否为素数的函数
    ......