头像

一塌糊涂




在线 


最近来访(307)
用户头像
林带王子
用户头像
Backlight
用户头像
straySheep.
用户头像
叶休
用户头像
MoonlightF
用户头像
Acolasia.漉奇
用户头像
Kam_1
用户头像
SYNUACM
用户头像
GritLs
用户头像
有时间多刷题
用户头像
MrYFX
用户头像
small_rubbish
用户头像
玄澈_
用户头像
Katharsis13
用户头像
晚柠
用户头像
ClockParadox
用户头像
懒懒散散的five
用户头像
锦木千束
用户头像
Mr.cat
用户头像
寒酥遇雪


一塌糊涂
15小时前

cpp dp

/*
x + x+d1 + x+d1+d2 +...+ x+d1+d2..+dn-1  =  s
n*x + (n-1)*d1 + (n-2)*d2  +...+ dn-1 = s

n*x = s - [(n-1)*d1 + (n-2)*d2  +...+ dn-1] 

n除过去  所以相当于 s%n == (n-1)*d1 + (n-2)*d2  +...+ dn-1 % n
*/

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 1010,P = 100000007;
int f[N][N];

//f[i][j] : 考虑d的前i项 modn = j 的方案数
//每次d选择有两种 +a -b 


int n,s,a,b;
int mod(int x){
    return (x%n + n)%n;
}

int main()
{

    cin>>n>>s>>a>>b;

    f[0][0] = 1; //边界条件

    for(int i=1;i<n;i++){
        for(int j=0;j<n;j++){ //因为数组 modn 同一为0-n-1之间
            f[i][j] = (f[i-1][mod(j-(n-i)*a)] + f[i-1][mod(j+(n-i)*b)] )%P;
        }
    }

    cout<<f[n-1][mod(s)]<<endl;
    return 0;
}



cpp 分组背包问题

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 110;
int v[N],w[N];
int f[N];

int main()
{
    int n,m;
    cin>>n>>m;

    for(int i=1;i<=n;i++)
    {
        int s;
        cin>>s;

        for(int j=0;j<s;j++) cin>>v[j]>>w[j];

        for(int j=m;j>=0;j--){
            for(int k=0;k<s;k++)
            if(j>=v[k]) f[j] = max(f[j],f[j-v[k]] + w[k]);
        }
    }

    cout<<f[m]<<endl;

    return 0;
}


活动打卡代码 AcWing 4473. 老板的作息表

cin.ignore():

ignore() 是 istream 类的成员函数,它的原型是:

istream & ignore(int n =1, int delim = EOF);

此函数的作用是跳过输入流中的 n 个字符,或跳过 delim 及其之前的所有字符,哪个条件先满足就按哪个执行。
两个参数都有默认值,因此 cin.ignore() 就等效于 cin.ignore(1, EOF), 即跳过一个字符。

该函数常用于跳过输入中的无用部分,以便提取有用的部分。
例如,输入的电话号码形式是Tel:63652823,Tel:就是无用的内容。

常用 getchar() 或者 cin.ignore() 在使用getline()之前吸收一个换行符

#include <iostream>
using namespace std;
int main()
{
    int n;
    cin.ignore(5, 'A');
    cin >> n;
    cout << n;
    return 0;
}

输入1:
abcde34↙
结果1:
34

cin.ignore() 跳过了输入中的前 5 个字符,其余内容被当作整数输入 n 中。

输入2
abA34↙
结果2:
34

cin.ignore() 跳过了输入中的 'A' 及其前面的字符,其余内容被当作整数输入 n 中。


活动打卡代码 AcWing 4471. 静静的推荐

cpp 模拟

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
#define x first
#define y second

using PII = pair<int,int>;
const int N = 1e5+10;
PII q[N];

bool cmp(int a,int b){
    return a>b;
}

int main()
{
    int n,k,s;
    cin>>n>>k>>s;
    for(int i=0;i<n;i++){
        int a,b ;
        cin>>a>>b;
        q[i] = {a,b};
    }

    sort(q,q+n);
    reverse(q,q+n);
    int cnt = 0;
    if(q[0].x >= 175) cnt++;

    int t = k;
    for(int i=1;i<n;i++){
        if(q[i].x != q[i-1].x && q[i].x >= 175) {
            cnt++;
            t = k;
        }
        else if(q[i].x == q[i-1].x && q[i].x >= 175){

            if(q[i].y >= s) {
                cnt++;

            }
            else if(t>0){
                cnt++;
                t--;
            }
            else continue;
        }
        else break;
    }

    cout<<cnt<<endl;
    return 0;
}



cpp 模拟

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 1e5+10;
bool r[N];
bool c[N];
int main()
{
    int n,m,q;
    cin>>n>>m>>q;
    while(q--){
        int t,k;
        cin>>t>>k;
        if(t == 0){
            if(!r[k]) n--; 
            r[k] = true;
        } 
        else {
            if(!c[k]) m--;
            c[k] = true;
        }
    }

    cout<<n*m<<endl;
    return 0;
}



cpp 模拟题

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    string s1 = "";
    string a1;
    cin>>a1;
    for (int i = 1; i < a1.size(); i++) {
        if (a1[i] % 2 == a1[i-1] % 2) {
            s1 += max(a1[i], a1[i-1]);
        }
    }

    string s2 = "";
    string a2;
    cin>>a2;
    for (int i = 1; i < a2.size(); i++) {
        if (a2[i] % 2 == a2[i-1] % 2) {
            s2 += max(a2[i], a2[i-1]);
        }
    }

    if(s1 == s2) cout<<s1<<endl;
    else {
        cout<<s1<<endl;
        cout<<s2<<endl;
    }


    return 0;
}


活动打卡代码 AcWing 4468. 试试手气

cpp 模拟题

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int q[6];
    for(int i=0;i<6;i++) cin>>q[i];

    int n;
    cin>>n;

    for(int i=0;i<6;i++){
       for(int j=6,cnt=0;j>=1;j--){
           if(q[i] != j && ++cnt == n) {
               cout<<j<<" ";
           }
       }
    }

    return 0;
}


活动打卡代码 AcWing 4467. 拯救外星人

cpp 模拟

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
#define int long long

signed main()
{
    int a,b;
    cin>>a>>b;

    int res = 1;
    for(int i=2;i<=a+b;i++){
        res *= i;
    }

    cout<<res<<endl;
    return 0;
}


活动打卡代码 AcWing 4466. 谁能进图书馆

cpp 模拟

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int mi,mx,t1,t2;
    cin>>mi>>mx>>t1>>t2;
    int tm,ti;
    bool flag = true;
    if(t1 > t2){
       tm = t1;
       ti = t2;
       flag = false;
    } 
    else {
        tm = t2;
        ti = t1;
    }
    if(ti >= mi ){
        cout<<t1<<"-Y"<<" "<<t2<<"-Y"<<endl;
        puts("huan ying ru guan");
    }
    else if(tm < mi){
         cout<<t1<<"-N"<<" "<<t2<<"-N"<<endl;
        puts("zhang da zai lai ba");
    }
    else if(tm < mx && tm >= mi){
        if(flag){
            cout<<t1<<"-N"<<" "<<t2<<"-Y"<<endl;
            puts("2: huan ying ru guan");
        } 
        else{
            cout<<t1<<"-Y"<<" "<<t2<<"-N"<<endl;
            puts("1: huan ying ru guan");
        } 
    }
    else {
         cout<<t1<<"-Y"<<" "<<t2<<"-Y"<<endl;
       if(flag){
           puts("qing 2 zhao gu hao 1");
       }
       else {
           puts("qing 1 zhao gu hao 2");
       }
    }

    return 0;
}


活动打卡代码 AcWing 4465. 种钻石

cpp 模拟

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int n,v;
    cin>>n>>v;
    cout<<n/v<<endl;

    return 0;
}