zoukankan      html  css  js  c++  java
  • Codeforces Round #277(Div. 2)

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int MAX = 1e5+10;
    int main() {
        LL n;
        while(cin>>n) {
            if(n&1) cout<<(n-1)/2-n<<endl;
            else cout<<n/2<<endl;
        }
    }

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int MAX = 1e2+10;
    const int MOD = 1e9+7;
    vector<int> G[MAX];
    int  a[MAX][MAX];
    int x[MAX];
    int use[MAX][MAX];
    int res[MAX][MAX];
    int check[MAX][MAX];
    int main() {
        int n,m;
        while(scanf("%d %d",&n,&m)==2) {
            memset(res,0,sizeof(res));
            for(int i=1;i<=n;i++) {
                for(int j=1;j<=m;j++) {
                    scanf("%d",&a[i][j]);
                }
            }
            for(int i=1;i<=n;i++) {
                for(int j=1;j<=m;j++) {

                    bool flag=true;
                    for(int k=1;k<=n;k++) {
                        if(!a[k][j]) flag=false;
                    }
                    for(int k=1;k<=m;k++) {
                        if(!a[i][k]) flag=false;
                    }
                    if(flag) res[i][j]=1;
                }
            }

            for(int i=1;i<=n;i++) {
                for(int j=1;j<=m;j++) {
                    int ans=0;
                    for(int k=1;k<=n;k++) {
                        ans|=res[k][j];
                    }
                    for(int k=1;k<=m;k++) {
                            ans|=res[i][k];

                    }
                    check[i][j]=ans;
                }
            }
            bool flag= true;
            for(int i=1;i<=n;i++) {
                for(int j=1;j<=m;j++) {
                    if(check[i][j]!=a[i][j]) {
                        flag=falsebreak;
                    }
                }
            }
            if(flag) {
                printf("YES ");
                for(int i=1;i<=n;i++) {
                    for(int j=1;j<=m;j++) {
                        printf("%d ",res[i][j]);
                    }
                    printf(" ");
                }
            }
            else printf("NO ");
        }
    }

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int MAX = 1e5+10;
    const int MOD = 1e9+7;
    char str[MAX];
    int main() {
        int n,p;
        int Max,Min,res;
        while(scanf("%d %d",&n,&p)==2) {
            scanf("%s",str+1);
            int len=strlen(str+1);
            if((p<<1)>n) p=len-p+1;
            Max=Min=p; res=0;
            for(int i=1;i*2<=n;i++) {
                if(str[i]!=str[n-i+1]) {
                    res+=min(abs(str[i]-str[n-i+1]),min(str[i]-'a',str[n-i+1]-'a')+26-max(str[i]-'a',str[n-i+1]-'a'));
                    Max=max(Max,i);
                    Min=min(Min,i);
                }
            }
            res+=min((p-Min),(Max-p))+(Max-Min);
            printf("%d ",res);
        }
        return 0;
    }

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int MAX = 2000+10;
    const int MOD = 1e9+7;
    int a[MAX],root;
    int d,n,u,v;
    vector<int> G[MAX];
    void init() {
        for(int i=0;i<MAX;i++) G[i].clear();
    }
    void add_edge(int from,int to) {
        G[from].push_back(to);
        G[to].push_back(from);
    }
    LL dfs(int u,int f) {
        LL ans=1;
        for(int i=0;i<G[u].size();i++) {
            int v=G[u][i];
            if(v==f||a[v]>a[root]||(a[root]==a[v]&&v>root)||a[root]-a[v]>d) continue;
            ans=(ans*(dfs(v,u)+1))%MOD; // 选或者不选两种状态
        }
        return ans;
    }
    int main() {
        while(scanf("%d %d",&d,&n)==2) {
            init();
            for(int i=1;i<=n;i++) {
                scanf("%d",&a[i]);
            }
            for(int i=1;i<n;i++) {
                scanf("%d %d",&u,&v);
                add_edge(u,v);
            }
            LL ans=0;
            for(int i=1;i<=n;i++) {
                root=i;
                LL res=dfs(i,-1);
                ans=(ans+res)%MOD;
            }
            printf("%I64d ",ans);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    设计模式整理_单例设计模式
    设计模式整理_工厂模式
    设计模式整理_装饰者模式
    设计模式整理_观察者模式
    设计模式整理_策略模式
    JavaSE复习_7 异常
    JavaSE复习_6 枚举类
    JavaSE复习_5 Eclipse的常见操作
    pta编程题19 Saving James Bond 2
    ImportError: No module named PIL
  • 原文地址:https://www.cnblogs.com/acvc/p/4092660.html
Copyright © 2011-2022 走看看