ABC-185(A~F)


比賽地址

個(gè)人博客

github


A

/*
 * Author: Moon-light
 * 按照題意輸出
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define lowbit(x) ((x)&(-x))
#define sz(x) ((int)x.size())
#define fr(x) freopen(x,'r',stdin)
#define fw(x) freopen(x,'w',stdout)
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define bitcnt(x) (__builtin_popcountll(x))
#define rep(i,a,b) for(int i = (a);i<=(b); ++i)
#define per(i,a,b) for(int i = (a);i>=(b); --i)
typedef long long LL;
typedef pair<int,int> PII;  
typedef pair<LL,LL> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VB;
typedef double db;

template <class T> void clear(T& a) { T().swap(a);}
template <class T,class S>
inline bool upmin(T& a,const S&b){ return a>b ? a=b,1:0;}
template <class T,class S>
inline bool upmax(T&a, const S&b){ return a<b? a=b,1:0;}

//fast read(improved by fread)
char buf[1<<21],*p1=buf,*p2=buf;
inline int getc(){
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
}
inline int redi() {
    int ret = 0,f = 0;char ch = getc();
    while (!isdigit (ch)) {
        if (ch == '-') f = 1;
        ch = getc();
    }
    while (isdigit (ch)) {
        ret = ret * 10 + ch - 48;
        ch = getc();
    }
    return f?-ret:ret;
}

//global variable
const int N = 1;
const int mod = 1e9+7;

//functions
LL qmi(LL a,LL k,LL mod){
    LL res = 1;
    while(k){
        if(k&1) res = res*a%mod;
        k >>= 1;
        a = a*a%mod;
    }
    return mod;
}
int gcd(int a,int b) {
    return b==0? a:gcd(b,a%b);
}
//


//code from here! Come on! Have a pleasant experience~
int main()
{
    IO;
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    cout<<min(a,min(b,min(c,d)))<<endl;
    return 0;
}

B

/*
 * Author: Moon-light
 * 按照題意邊模擬邊判斷即可
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define lowbit(x) ((x)&(-x))
#define sz(x) ((int)x.size())
#define fr(x) freopen(x,'r',stdin)
#define fw(x) freopen(x,'w',stdout)
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define bitcnt(x) (__builtin_popcountll(x))
#define rep(i,a,b) for(int i = (a);i<=(b); ++i)
#define per(i,a,b) for(int i = (a);i>=(b); --i)
typedef long long LL;
typedef pair<int,int> PII;  
typedef pair<LL,LL> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VB;
typedef double db;

template <class T> void clear(T& a) { T().swap(a);}
template <class T,class S>
inline bool upmin(T& a,const S&b){ return a>b ? a=b,1:0;}
template <class T,class S>
inline bool upmax(T&a, const S&b){ return a<b? a=b,1:0;}

//fast read(improved by fread)
char buf[1<<21],*p1=buf,*p2=buf;
inline int getc(){
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
}
inline int redi() {
    int ret = 0,f = 0;char ch = getc();
    while (!isdigit (ch)) {
        if (ch == '-') f = 1;
        ch = getc();
    }
    while (isdigit (ch)) {
        ret = ret * 10 + ch - 48;
        ch = getc();
    }
    return f?-ret:ret;
}

//global variable
const int N = 1;
const int mod = 1e9+7;

//functions
LL qmi(LL a,LL k,LL mod){
    LL res = 1;
    while(k){
        if(k&1) res = res*a%mod;
        k >>= 1;
        a = a*a%mod;
    }
    return mod;
}
int gcd(int a,int b) {
    return b==0? a:gcd(b,a%b);
}
//
LL m,n,t;
LL a,b;

//code from here! Come on! Have a pleasant experience~
int main()
{
    IO;
    cin>>n>>m>>t;
    
    LL left = n;
    LL last = 0;
    m -= 1;
    cin>>a>>b;
    left -= a;
    if(left <= 0) {
        cout<<"No"<<endl;
        return 0;
    }
    left += (b-a);
    last = b;
    if(left > n) left = n;
    for(int i = 1; i<=m; i++){
        cin>>a>>b;
        left = left - (a-last);
        if(left <= 0) {
            cout<<"No"<<endl;
            return 0;
        }
        left = left + (b-a);
        if(left > n) left = n;
        last = b;
    }
    
    left = left - (t-last);
    if(left <= 0){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
    return 0;
}

C

/*
 * Author: Moon-light
 * 題意:一根木棍分成12段的切法數(shù)量,兩種切法不同當(dāng)且僅當(dāng)切割的位置不同
 * 求組合數(shù)即可士修,注意一個(gè)木棍可切割的位置是n-1
 * 那么answer = C(11,n-1);
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define lowbit(x) ((x)&(-x))
#define sz(x) ((int)x.size())
#define fr(x) freopen(x,'r',stdin)
#define fw(x) freopen(x,'w',stdout)
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define bitcnt(x) (__builtin_popcountll(x))
#define rep(i,a,b) for(int i = (a);i<=(b); ++i)
#define per(i,a,b) for(int i = (a);i>=(b); --i)
typedef long long LL;
typedef pair<int,int> PII;  
typedef pair<LL,LL> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VB;
typedef double db;

template <class T> void clear(T& a) { T().swap(a);}
template <class T,class S>
inline bool upmin(T& a,const S&b){ return a>b ? a=b,1:0;}
template <class T,class S>
inline bool upmax(T&a, const S&b){ return a<b? a=b,1:0;}

//fast read(improved by fread)
char buf[1<<21],*p1=buf,*p2=buf;
inline int getc(){
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
}
inline int redi() {
    int ret = 0,f = 0;char ch = getc();
    while (!isdigit (ch)) {
        if (ch == '-') f = 1;
        ch = getc();
    }
    while (isdigit (ch)) {
        ret = ret * 10 + ch - 48;
        ch = getc();
    }
    return f?-ret:ret;
}

//global variable
const int N = 300;
const int mod = 1e9+7;
LL c[N][N];
int n;
//functions
LL qmi(LL a,LL k,LL mod){
    LL res = 1;
    while(k){
        if(k&1) res = res*a%mod;
        k >>= 1;
        a = a*a%mod;
    }
    return mod;
}
int gcd(int a,int b) {
    return b==0? a:gcd(b,a%b);
}

void solve(){
    for(int i = 0; i<N; i++){
        for(int j = 0; j<=i; j++){
            if(!j) c[i][j] = 1;
            else c[i][j] = c[i-1][j] + c[i-1][j-1];
        }
    }
}
//

//code from here! Come on! Have a pleasant experience~
int main()
{
    IO;
    cin>>n;
    solve();
    cout<<c[n-1][11]<<endl;
    return 0;
}

D

/*
 * Author: Moon-light
 * 
 * 思路:因?yàn)椴荒芘龅剿{(lán)色的方塊,所以我們只能找藍(lán)色方塊分割開的白色序列中找最小的連續(xù)的子序列
 * 然后求次數(shù)即可,注意首尾的邊界情況
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define lowbit(x) ((x)&(-x))
#define sz(x) ((int)x.size())
#define fr(x) freopen(x,'r',stdin)
#define fw(x) freopen(x,'w',stdout)
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define bitcnt(x) (__builtin_popcountll(x))
#define rep(i,a,b) for(int i = (a);i<=(b); ++i)
#define per(i,a,b) for(int i = (a);i>=(b); --i)
typedef long long LL;
typedef pair<int,int> PII;  
typedef pair<LL,LL> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VB;
typedef double db;

template <class T> void clear(T& a) { T().swap(a);}
template <class T,class S>
inline bool upmin(T& a,const S&b){ return a>b ? a=b,1:0;}
template <class T,class S>
inline bool upmax(T&a, const S&b){ return a<b? a=b,1:0;}

//fast read(improved by fread)
char buf[1<<21],*p1=buf,*p2=buf;
inline int getc(){
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
}
inline int redi() {
    int ret = 0,f = 0;char ch = getc();
    while (!isdigit (ch)) {
        if (ch == '-') f = 1;
        ch = getc();
    }
    while (isdigit (ch)) {
        ret = ret * 10 + ch - 48;
        ch = getc();
    }
    return f?-ret:ret;
}

//global variable
const int N = 2e5+100;
const int mod = 1e9+7;
LL n,m;
LL a[N];


//functions
LL qmi(LL a,LL k,LL mod){
    LL res = 1;
    while(k){
        if(k&1) res = res*a%mod;
        k >>= 1;
        a = a*a%mod;
    }
    return mod;
}
int gcd(int a,int b) {
    return b==0? a:gcd(b,a%b);
}
//


//code from here! Come on! Have a pleasant experience~
int main()
{
    IO;
    cin>>n>>m;

    for(int i = 1; i<=m; i++){
        cin>>a[i];
    }   
    sort(a+1,a+1+m);

    if(m == 0){
        cout<<1<<endl;
        return 0;
    }
    if(n == m) {
        cout<<0<<endl;
        return 0;
    }
    
    LL range = a[1] - 1;
    LL last = a[1];
    for(int i = 2; i<=m; i++){
        LL t = a[i] - last - 1;
        if(range  == 0) range = t;
        else if(t > 0) range = min(range,t);
        last = a[i];
    }
    if(n > last){
        if(range == 0) range = (n-last);
        else range = min(range,n-last);
    }
        
    //cout<<range<<endl;
    LL ans = 0;
    last = a[1];
    if(a[1] > 1){
        ans += (a[1]-2)/range+1;
    }
    for(int i = 2; i<=m; i++){
        int cnt = a[i]-last-1;
        ans += (cnt-1)/range+1;
        last = a[i];
    }
    if(n>last)
        ans += (n-last-1)/range + 1;
    cout<<ans<<endl; 
    return 0;
}

E

/*
 * Author: Moon-light
 * 
 * 題意: 有兩個(gè)長度分別為N和M的序列A,B
 * 刪除序列A中的a個(gè)元素得到A' , 0<=a<=N
 * 刪除序列B中的b個(gè)元素得到B' , 0<=b<=M
 * 使得A'的長度等于B'的長度
 * 令x = a + b
 *   y = Sum of i A'i != B'i 
 * 
 * 思路: 編輯距離模型
 * 設(shè)dp[i][j] 表示對(duì)A前i個(gè)及對(duì)B前j個(gè)元素的最小答案
 * 那么對(duì)于當(dāng)前的A[i]和 B[j]
 * 有三種情況: 1.刪除A[i],保留B[j] dp[i-1][j] + 1
 *              2.保留A[i],刪除B[j] dp[i][j-1] + 1
 *              3.保留A[i], 保留A[j] dp[i-1][j-1] + (a[i]==b[j]?0:1)
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define lowbit(x) ((x)&(-x))
#define sz(x) ((int)x.size())
#define fr(x) freopen(x,'r',stdin)
#define fw(x) freopen(x,'w',stdout)
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define bitcnt(x) (__builtin_popcountll(x))
#define rep(i,a,b) for(int i = (a);i<=(b); ++i)
#define per(i,a,b) for(int i = (a);i>=(b); --i)
typedef long long LL;
typedef pair<int,int> PII;  
typedef pair<LL,LL> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VB;
typedef double db;

template <class T> void clear(T& a) { T().swap(a);}
template <class T,class S>
inline bool upmin(T& a,const S&b){ return a>b ? a=b,1:0;}
template <class T,class S>
inline bool upmax(T&a, const S&b){ return a<b? a=b,1:0;}

//fast read(improved by fread)
char buf[1<<21],*p1=buf,*p2=buf;
inline int getc(){
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
}
inline int redi() {
    int ret = 0,f = 0;char ch = getc();
    while (!isdigit (ch)) {
        if (ch == '-') f = 1;
        ch = getc();
    }
    while (isdigit (ch)) {
        ret = ret * 10 + ch - 48;
        ch = getc();
    }
    return f?-ret:ret;
}

//global variable
const int N = 1010;
const int mod = 1e9+7;

int n,m;
int a[N],b[N];
int dp[N][N];

//functions
LL qmi(LL a,LL k,LL mod){
    LL res = 1;
    while(k){
        if(k&1) res = res*a%mod;
        k >>= 1;
        a = a*a%mod;
    }
    return mod;
}
int gcd(int a,int b) {
    return b==0? a:gcd(b,a%b);
}
//


//code from here! Come on! Have a pleasant experience~
int main()
{
    IO;
    cin>>n>>m;

    rep(i,1,n) cin>>a[i];
    rep(i,1,m) cin>>b[i];

    //initialization
    rep(i,1,n) dp[i][0] = i;
    rep(i,1,m) dp[0][i] = i;

    rep(i,1,n){
        rep(j,1,m){
            //刪一個(gè)
            dp[i][j] = min(dp[i-1][j]+1,dp[i][j-1]+1);
            //不刪
            dp[i][j] = min(dp[i][j], dp[i-1][j-1] + (a[i]==b[j]?0:1));
        }
    }
    cout<<dp[n][m];
    return 0;
}

F

/*
 * Author: Moon-light
 * 題意: 1.單點(diǎn)修改 Ax = Ax ^ Y
 *       2.區(qū)間查詢 Ax1 ^ Ax2 ^ Ax3 ^... ^ Ay
 * 
 * 思路: 樹狀數(shù)組模板
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define lowbit(x) ((x)&(-x))
#define sz(x) ((int)x.size())
#define fr(x) freopen(x,'r',stdin)
#define fw(x) freopen(x,'w',stdout)
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define bitcnt(x) (__builtin_popcountll(x))
#define rep(i,a,b) for(int i = (a);i<=(b); ++i)
#define per(i,a,b) for(int i = (a);i>=(b); --i)
typedef long long LL;
typedef pair<int,int> PII;  
typedef pair<LL,LL> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VB;
typedef double db;

template <class T> void clear(T& a) { T().swap(a);}
template <class T,class S>
inline bool upmin(T& a,const S&b){ return a>b ? a=b,1:0;}
template <class T,class S>
inline bool upmax(T&a, const S&b){ return a<b? a=b,1:0;}

//fast read(improved by fread)
char buf[1<<21],*p1=buf,*p2=buf;
inline int getc(){
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
}
inline int redi() {
    int ret = 0,f = 0;char ch = getc();
    while (!isdigit (ch)) {
        if (ch == '-') f = 1;
        ch = getc();
    }
    while (isdigit (ch)) {
        ret = ret * 10 + ch - 48;
        ch = getc();
    }
    return f?-ret:ret;
}

//global variable
const int N = 3e5+100;
const int mod = 1e9+7;
int n,q,t,x,y;
int tr[N];

//functions
LL qmi(LL a,LL k,LL mod){
    LL res = 1;
    while(k){
        if(k&1) res = res*a%mod;
        k >>= 1;
        a = a*a%mod;
    }
    return mod;
}
int gcd(int a,int b) {
    return b==0? a:gcd(b,a%b);
}

void update(int u,int x){
    for(int i = u; i<=n; i+=lowbit(i)){
        tr[i] ^= x;
    }
}

int query(int x){
    int res = 0;
    for(int i = x; i; i-=lowbit(i)){
        res ^= tr[i];
    }
    return res;
}
//


//code from here! Come on! Have a pleasant experience~
int main()
{
    IO;
    cin>>n>>q;
    rep(i,1,n){
        cin>>x;
        update(i,x);
    }

    rep(i,1,q){
        cin>>t>>x>>y;
        if(t == 1){
            update(x,y);
        }else{
            cout<<(query(y)^query(x-1))<<endl;
        }
    }
    return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末泻帮,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子计寇,更是在濱河造成了極大的恐慌锣杂,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,941評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件番宁,死亡現(xiàn)場(chǎng)離奇詭異元莫,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)蝶押,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,397評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門踱蠢,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人棋电,你說我怎么就攤上這事茎截。” “怎么了离陶?”我有些...
    開封第一講書人閱讀 165,345評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵稼虎,是天一觀的道長。 經(jīng)常有香客問我招刨,道長霎俩,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,851評(píng)論 1 295
  • 正文 為了忘掉前任沉眶,我火速辦了婚禮打却,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘谎倔。我一直安慰自己柳击,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,868評(píng)論 6 392
  • 文/花漫 我一把揭開白布片习。 她就那樣靜靜地躺著捌肴,像睡著了一般蹬叭。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上状知,一...
    開封第一講書人閱讀 51,688評(píng)論 1 305
  • 那天秽五,我揣著相機(jī)與錄音,去河邊找鬼饥悴。 笑死坦喘,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的西设。 我是一名探鬼主播瓣铣,決...
    沈念sama閱讀 40,414評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼贷揽!你這毒婦竟也來了棠笑?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,319評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤禽绪,失蹤者是張志新(化名)和其女友劉穎腐晾,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體丐一,經(jīng)...
    沈念sama閱讀 45,775評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡藻糖,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,945評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了库车。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片巨柒。...
    茶點(diǎn)故事閱讀 40,096評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖柠衍,靈堂內(nèi)的尸體忽然破棺而出洋满,到底是詐尸還是另有隱情,我是刑警寧澤珍坊,帶...
    沈念sama閱讀 35,789評(píng)論 5 346
  • 正文 年R本政府宣布牺勾,位于F島的核電站,受9級(jí)特大地震影響阵漏,放射性物質(zhì)發(fā)生泄漏驻民。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,437評(píng)論 3 331
  • 文/蒙蒙 一履怯、第九天 我趴在偏房一處隱蔽的房頂上張望回还。 院中可真熱鬧,春花似錦叹洲、人聲如沸柠硕。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,993評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽蝗柔。三九已至闻葵,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間癣丧,已是汗流浹背笙隙。 一陣腳步聲響...
    開封第一講書人閱讀 33,107評(píng)論 1 271
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留坎缭,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,308評(píng)論 3 372
  • 正文 我出身青樓签钩,卻偏偏與公主長得像掏呼,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子铅檩,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,037評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容