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

    http://codeforces.com/contest/731

    不发题面了,自己点链接

    总结一下

    考场上

    原以为这次要加很多raiting。。。

    但FST狗记邓,只加了58rating

    总结一下

    • ABC切得很快(保持)
    • B题WA了2发不应该,没有想清楚
    • F题写了大暴力,但不优美,虽然过了P,但就没有想了,很严重问题,得意忘形,虽然知道FST,但有侥幸心里,真正考试就完了
    • 以为拿到了分就不干事了,严重问题,真正考试一定要写暴力拍
    • 后来没有干事,既没有hack又没有去写DE不应该

    A Night at the Museum

    Solution:Implementation,String

    // <A.cpp> - Sun Oct 16 17:45:40 2016
    // This file is made by YJinpeng,created by XuYike's black technology automatically.
    // Copyright (C) 2016 ChangJun High School, Inc.
    // I don't know what this program is.
    
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #define MOD 1000000007
    #define INF 1e9
    using namespace std;
    typedef long long LL;
    const int MAXN=110;
    inline int gi() {
    	register int w=0,q=0;register char ch=getchar();
    	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    	if(ch=='-')q=1,ch=getchar();
    	while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
    	return q?-w:w;
    }
    char s[MAXN];
    int main()
    {
    	freopen("A.in","r",stdin);
    	freopen("A.out","w",stdout);
    	scanf("%s",s);int l=strlen(s);
        char ch='a';int ans=0;
        for(int i=0;i<l;i++)
            ans+=min((s[i]-ch+26)%26,(ch-s[i]+26)%26),ch=s[i];
        printf("%d",ans);
    	return 0;
    }
    

    B Coupons and Discounts

    题目大意:每天要买a[i]个东西,买的方式有两种:两天一天买一个 or 一天买两个,问是否有合法方案

    Solution:Greedy+递推,考虑一天,奇数的话必须要用第一种方式,那就之后那天要买一个,几个flag即可,一路推过去,<0不合法,偶数的话直接用第二种→ 贪心,不用麻烦后面那天。

    反思:居然wa了两发,7~80分啊。。(notice 最后一次是否要之后填充,flag清空)

    // <B.cpp> - Sun Oct 16 17:45:40 2016
    // This file is made by YJinpeng,created by XuYike's black technology automatically.
    // Copyright (C) 2016 ChangJun High School, Inc.
    // I don't know what this program is.
    
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #define MOD 1000000007
    #define INF 1e9
    using namespace std;
    typedef long long LL;
    const int MAXN=100010;
    const int MAXM=100010;
    inline int gi() {
    	register int w=0,q=0;register char ch=getchar();
    	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    	if(ch=='-')q=1,ch=getchar();
    	while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
    	return q?-w:w;
    }
    void pri(){printf("NO");exit(0);}
    int main()
    {
    	freopen("B.in","r",stdin);
    	freopen("B.out","w",stdout);
    	int n=gi(),last=0;
        for(int i=1;i<=n;i++){
            int x=gi()-last;
            if(x<0)pri();
            if(x&1)last=1;else last=0;
        }if(last)pri();else printf("YES");
        return 0;
    }
    

    C Socks

    有n只袜子,每只袜子有一个颜色,有一些约束(即某天的左右两边袜子颜色要相同),然后问你最少要改多少只?

    显然并查集,然后贪心,一个联通块内的颜色要全相同,Greedy-找出颜色已经相同的最多数目,答案加上其他要改的即可

    // <C.cpp> - Sun Oct 16 17:45:40 2016
    // This file is made by YJinpeng,created by XuYike's black technology automatically.
    // Copyright (C) 2016 ChangJun High School, Inc.
    // I don't know what this program is.
    
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #define MOD 1000000007
    #define INF 1e9
    using namespace std;
    typedef long long LL;
    const int MAXN=200010;
    inline int gi() {
    	register int w=0,q=0;register char ch=getchar();
    	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    	if(ch=='-')q=1,ch=getchar();
    	while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
    	return q?-w:w;
    }
    int f[MAXN],a[MAXN],c[MAXN];vector<int>b[MAXN];
    int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
    int main()
    {
    	freopen("C.in","r",stdin);
    	freopen("C.out","w",stdout);
    	int n=gi(),m=gi(),k=gi(),ans=0;k++;
        for(int i=1;i<=n;i++)a[i]=gi(),f[i]=i;
        while(m--){
            int l=gi(),r=gi();
            if(find(l)!=find(r))f[f[l]]=f[r];
        }
        for(int i=1;i<=n;i++)
            b[find(i)].push_back(i);
        for(int i=1;i<=n;i++){
            if(f[i]!=i)continue;int now=0;
            for(int j=0,to=b[i].size();j<to;j++){
                c[a[b[i][j]]]++;
                if(c[a[b[i][j]]]>now)now=c[a[b[i][j]]];
            }
            ans+=b[i].size()-now;
            for(int j=0,to=b[i].size();j<to;j++)c[a[b[i][j]]]--;
        }printf("%d",ans);
    	return 0;
    }
    

    D

    挖坑~

    E

    挖坑~

    F Video Cards

    给你一列数a[],选择一个标准,使得其他的数减小至他的倍数,使得和最大?

    CF给的标签:brute force(暴力)implementation(实现)number theory(数论)-醉了
    F是个送肉题。。。FST。。。。
    直接看代码吧
    暴力也分优美与垃圾
    TLE on Test 23(P都过了,2×10^5都过了,结果FST,10^4没过)-暴力加break
    // <F.cpp> - Sun Oct 16 17:45:40 2016
    // This file is made by YJinpeng,created by XuYike's black technology automatically.
    // Copyright (C) 2016 ChangJun High School, Inc.
    // I don't know what this program is.
    
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    using namespace std;
    typedef long long LL;
    const int MAXN=200010;
    inline int gi() {
    	register int w=0,q=0;register char ch=getchar();
    	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    	if(ch=='-')q=1,ch=getchar();
    	while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
    	return q?-w:w;
    }
    int a[MAXN];LL f[MAXN];
    int main()
    {
    	int n=gi();LL ans=0;
        for(int i=1;i<=n;i++)a[i]=gi();
        sort(a+1,a+1+n);
        for(int i=1;i<=n;i++)f[i]=f[i-1]+a[i];
        for(int i=1;i<=n;i++){
            LL now=a[i];
            for(int j=n;j>i;j--){
                if(now+f[j]-f[i]<=ans)break;
                now+=a[j]/a[i]*a[i];
            }
            if(now>ans)ans=now;
        }printf("%I64d",ans);
    	return 0;
    }
    

    AC-暴力+统计

    // <F.cpp> - Sun Oct 16 17:45:40 2016
    // This file is made by YJinpeng,created by XuYike's black technology automatically.
    // Copyright (C) 2016 ChangJun High School, Inc.
    // I don't know what this program is.
    
    
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    using namespace std;
    typedef long long LL;
    const int MAXN=200001;
    inline int gi() {
    	register int w=0,q=0;register char ch=getchar();
    	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    	if(ch=='-')q=1,ch=getchar();
    	while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
    	return q?-w:w;
    }
    LL s[MAXN];int a[MAXN];
    int main()
    {
    	freopen("F.in","r",stdin);
    	freopen("F.out","w",stdout);
    	int n=gi();LL ans=0;
        for(int i=1;i<=n;i++)a[gi()]++;
        for(int i=1;i<MAXN;i++)s[i]=s[i-1]+a[i];
        for(int i=1;i<MAXN;i++)
            if(a[i]){
                LL now=0;int t=MAXN/i;
                for(int j=1;j<t;j++)
                    now+=1LL*(s[i*(j+1)-1]-s[i*j-1])*j*i;
                now+=1LL*(s[MAXN-1]-s[i*t-1])*i*t;
                if(now>ans)ans=now;
            }
        printf("%lld",ans);
    	return 0;
    }
    

      

     

  • 相关阅读:
    在Azure虚拟机上安装SQL server
    Azure的负载均衡机制
    如何在ARM中创建Express Route
    如何将已部署在ASM的资源迁移到ARM中
    Azure上的那些IP
    使用mysqlslap对mysql进行压测,观察Azure虚拟机cpu使用率
    在Azure虚拟机上安装VNC
    DataGridView中实现checkbox全选的自定义控件
    jquery checkbox 实现单选
    如何通过Azure Service Management REST API管理Azure服务
  • 原文地址:https://www.cnblogs.com/YJinpeng/p/5973304.html
Copyright © 2011-2022 走看看