2018 “百度之星”程序设计大赛 - 初赛(A)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/algzjh/article/details/81591610

1001度度熊拼三角

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int MAXN=1e5+5;
const int INF=0x3f3f3f3f;
int a[MAXN];

int main(){
    //int _;
    //scanf("%d",&_);
    int n;
    while(~scanf("%d",&n)){
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        //a+b>c;
        //b-a<c
        int ans=-1;
        int x,y,z;
        sort(a+1,a+n+1);
        for(int i=1;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                x=a[i];
                y=a[j];
                int pos=upper_bound(a+j+1,a+n+1,x+y)-(a);
                pos--;
                if(pos>j&&x+y>a[pos]&&y-x<a[pos]&&a[pos]-x<y&&a[pos]-y<x){
                    ans=max(ans,x+y+a[pos]);
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

1002度度熊学队列
list.splice

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<list>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int MAXN=2e5+5;
const int INF=0x3f3f3f3f;
int n,q;

struct Node{
    list<int> L;
    list<int> rL;
}a[MAXN];

void read(int &x){
    char ch = getchar();x = 0;
    for (; ch < '0' || ch > '9'; ch = getchar());
    for (; ch >='0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}

void init(){
    for(int i=1;i<=n;i++){
        //a[i].head=a[i].tail=0;
        a[i].L.clear();
        a[i].rL.clear();
    }
}

int main(){
    while(~scanf("%d%d",&n,&q)){
        init();
        int op;
        while(q--){
            //read(op);
            scanf("%d",&op);
            int u,v,w,val;
            list<int>::iterator it;
            if(op==1){
                //read(u);read(v);read(val);
                scanf("%d%d%d",&u,&w,&val);
                if(w==0){
                    a[u].L.push_front(val);
                    a[u].rL.push_back(val);
                }else{
                    a[u].L.push_back(val);
                    a[u].rL.push_front(val);
                }
            }else if(op==2){
                //read(u);read(w);
                scanf("%d%d",&u,&w);
                if(a[u].L.empty()){
                    printf("-1\n");
                }else if(w==0){
                    printf("%d\n",a[u].L.front());
                    a[u].L.pop_front();
                    a[u].rL.pop_back();
                }else{
                    printf("%d\n",a[u].L.back());
                    a[u].L.pop_back();
                    a[u].rL.pop_front();
                }
            }else{
                //read(u);read(v);read(w);
                scanf("%d%d%d",&u,&v,&w);
                if(w==0){
                    it=a[u].L.end();
                    a[u].L.splice(it,a[v].L);
                    it=a[u].rL.begin();
                    a[u].rL.splice(it,a[v].rL);
                }else{
                    it=a[u].L.end();
                    a[u].L.splice(it,a[v].rL);
                    it=a[u].rL.begin();
                    a[u].rL.splice(it,a[v].L);
                }
            }
//            cout<<"-----L----"<<endl;
//            for(it=a[u].L.begin();it!=a[u].L.end();it++){
//                cout<<*it<<" ";
//            }
//            cout<<endl;
//            cout<<"-----rL------"<<endl;
//            for(it=a[u].rL.begin();it!=a[u].rL.end();it++){
//                cout<<*it<<" ";
//            }
//            cout<<endl;
        }
    }
    return 0;
}
/*
4 100
1 1 2
*/

1004度度熊看球赛
OEISA193639

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<list>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int MAXN=2e3+100;
const int INF=0x3f3f3f3f;
const int MOD=998244353;
LL T[MAXN][MAXN];

LL qpow(LL x,LL y){
    LL res=1;
    while(y){
        if(y&1) res=res*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return res;
}

void init(){
    memset(T,0,sizeof(T));
    T[0][0]=1;T[1][0]=0;T[1][1]=2;
    for(int i=2;i<=1000;i++){
        T[i][0]= 2*i*((2*i-1)*T[i-1][0]%MOD + (2*i-2)*T[i-2][0]%MOD)%MOD;
        for(int j=1;j<=i;j++){
            T[i][j] = 2*(2*i-j)*T[i-1][j-1]%MOD;
            T[i][j] = (T[i][j] + ((2*i-1-j)*(2*i-2-j)%MOD+2*j)%MOD*T[i-1][j])%MOD;
            T[i][j] = (T[i][j] + 2*(j+1)*(2*i-2-j)*T[i-1][j+1]%MOD)%MOD;
            T[i][j] = (T[i][j] + (j+2)*(j+1)*T[i-1][j+2]%MOD)%MOD;
        }
    }
}

int main(){
    init();
    int n,d;
    while(~scanf("%d%d",&n,&d)){
        LL ans=0;
        for(int k=0;k<=n;k++){
            ans=(ans+T[n][k]*qpow(d,k)%MOD)%MOD;
        }
        printf("%lld\n",ans);
    }
    return 0;
}
/*
1 10
2 3
*/
阅读更多

扫码向博主提问

algzjh

非学,无以致疑;非问,无以广识
  • 擅长领域:
  • ACM
去开通我的Chat快问
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页