跳到正文

个人记录

代码集

daiiiii0331约 10 分钟
原文
文章信息与版本

文章信息

发布
2026年11月21日
收录
2026年11月21日
更新
2026年11月22日
篇幅
约 10 分钟

版本

  1. v1当前

AC 的代码都放在这里

B4077 [CSP-X2019 山东] 鼓掌

C++
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define str std::string
ll x,y,n;
int main(){
    cin>>x>>y>>n;
    ll ggg=x*y/__gcd(x,y);
    ll ans=n/x+n/y-n/ggg;
    cout<<ans;
    return 0;
}

B4075 [CSP-X 2018] 11 的倍数

C++
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define str std::string
#define 输入 std::cin>>
#define 分号 ;
#define 给我 return
#define AC 0
#define 定义整数 long long
#define 定义字符串 std::string
#define 输出 std::cout<<
#define 循环 for
#define 左括号 (
#define 右括号 )
#define 零 0
#define 壹 1
#define 一 1
#define 二 2
#define 贰 2
#define 设为 =
#define 加上 +=
#define 自增 ++
#define 减去 -=
#define 自减 --
#define 模 %
#define 等于 ==
#define 小于 <
#define 小于等于 <=
#define 不大于 <=
#define 大于等于 >=
#define 不小于 >=
#define 不等于 !=
#define 反转 !
#define 整型 int
#define 左大括号 {
#define 右大括号 }
#define 左中括号 [
#define 右中括号 ]
#define 逗号 ,
#define 右移 >>
#define 左移 <<
#define 长度 size
#define 如果 if
#define 否则 else
#define 减 -
#define 加 +
#define 乘 *
#define 除以 /
#define 乘上 *=
#define 除去 /=
#define 模去 %=

定义整数 n 分号
定义字符串 s 分号
定义整数 c1 逗号 c2 分号
整型 main 左括号 右括号 左大括号
    输入 n 分号
    循环 左括号 定义整数 i 设为 壹 分号 i 不大于 n 分号 自增 i 右括号 左大括号
        输入 s 分号
        c1 设为 c2 设为 零 分号
        定义整数 sl 设为 s.size() 分号
        循环 左括号 定义整数 j 设为 零 分号 j 小于 sl 分号 自增 j 右括号 左大括号
            如果 左括号 左括号 sl 减 j 右括号 模 贰 等于 壹 右括号 左大括号
                c1 加上 s 左中括号 j 右中括号 减 '0' 分号
            右大括号 否则 左大括号
                c2 加上 s 左中括号 j 右中括号 减 '0' 分号
            右大括号
        右大括号
        如果 左括号 c1 模 11 等于 c2 模 11 右括号 左大括号
            输出 "Yes\n" 分号
        右大括号 否则 左大括号
            输出 "No\n" 分号
        右大括号
    右大括号
    给我 AC 分号
右大括号

P1236 算24点

C++
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define str string
#define lf double
ll a[5];
char c[5]={',','+','-','*','/'};
bool bj;
void meow(ll x,ll cc,ll y,ll z){
    cout<<max(x,y)<<c[cc]<<min(x,y)<<'='<<z<<'\n';
}
void qaq(ll b[]){
    ll ans=b[1];
    ll an1,an2;
    for(ll c1=1;c1<=4;++c1){
        for(ll c2=1;c2<=4;++c2){
            for(ll c3=1;c3<=4;++c3){
            	ans=b[1]; 
                if(c1==1)ans+=b[2];
                else if(c1==2)ans-=b[2];
                else if(c1==3)ans*=b[2];
                else if(ans%b[2]==0)ans/=b[2];
                else continue;
                if(ans<0)ans=-ans;
                else if(!ans)continue;
                an1=ans;
                if(c2==1)ans+=b[3];
                else if(c2==2)ans-=b[3];
                else if(c2==3)ans*=b[3];
                else if(ans%b[3]==0)ans/=b[3];
                else continue;
                if(ans<0)ans=-ans;
                else if(!ans)continue;
                an2=ans;
                if(c3==1)ans+=b[4];
                else if(c3==2)ans-=b[4];
                else if(c3==3)ans*=b[4];
                else if(ans%b[4]==0)ans/=b[4];
                else continue;
                if(ans==24){
                    meow(b[1],c1,b[2],an1);
                    meow(an1,c2,b[3],an2);
                    meow(an2,c3,b[4],ans);
                    bj=1;
                    return ;
                }
            }
        }
    }
    
    for(ll c1=1;c1<=4;++c1){
        for(ll c2=1;c2<=4;++c2){
            for(ll c3=1;c3<=4;++c3){
            	an1=b[1],an2=b[3];
                if(c1==1)an1+=b[2];
                else if(c1==2)an1-=b[2];
                else if(c1==3)an1*=b[2];
                else if(an1%b[2]==0)an1/=b[2];
                else continue;
                if(an1<0)an1=-an1; 
                else if(!an1)continue;
                if(c2==1)an2+=b[4];
                else if(c2==2)an2-=b[4];
                else if(c2==3)an2*=b[4];
                else if(an2%b[4]==0)an2/=b[4];
                else continue;
                if(an2<0)an2=-an2;
                else if(!an2)continue;
                if(c3==1)ans=an1+an2;
                else if(c3==2)ans=max(an1,an2)-min(an1,an2);
                else if(c3==3)ans=an1*an2;
                else if(an1%an2==0)ans=an1/an2;
                else if(an2%an1==0)ans=an2/an1;
                else continue;
                if(ans==24){
                    meow(b[1],c1,b[2],an1);
                    meow(b[3],c2,b[4],an2);
                    meow(an1,c3,an2,ans);
                    bj=1;
                    return ;
                }
            }
        }
    }
}
int main(){
    bj=0;
    cin>>a[1]>>a[2]>>a[3]>>a[4];
    ll b[5]={a[0],a[1],a[2],a[3],a[4]};
    for(ll i=1;i<=4;++i){
        for(ll j=1;j<=4;++j){
            for(ll k=1;k<=4;++k){
                ll ooo=1+2+3+4-i-j-k;
                if(i!=j&&i!=k&&i!=ooo&&j!=k&&j!=ooo&&k!=ooo){
                    b[1]=a[i],b[2]=a[j],b[3]=a[k],b[4]=a[ooo];
                    //cout<<b[1]<<' '<<b[2]<<' '<<b[3]<<' '<<b[4]<<'\n';
                    qaq(b);
                    if(bj)return 0;
                }
                
            }
        }
    }
    cout<<"No answer!";
    return 0;
}
原文