zoukankan      html  css  js  c++  java
  • CCPC长春赛重现

    比赛链接
    http://acm.hdu.edu.cn/contests/contest_show.php?cid=728

    QUALITY的题解
    https://async.icpc-camp.org/d/582-2016

    02

    分数加法除法,对着公式模拟即可

    #include <iostream>
    #include <cstdio>
    using namespace std;
    typedef long long LL;
    LL gcd (LL a,LL b){
        return b==0?a:gcd(b,a%b);
    }
    struct fenshu{
        LL fz,fm;
        fenshu (){fz = 0;fm = 1;}
        fenshu (LL x,LL y):fz(x),fm(y){}
        fenshu operator + (const fenshu &a)const{
            LL FM = fm*a.fm/gcd(fm,a.fm) ;
            LL FZ = fz*FM/fm+a.fz*FM/a.fm;
            return fenshu{FZ,FM};
        }
        fenshu operator / (const fenshu &a)const{
            LL FZ = fz*a.fm;
            LL FM = fm*a.fz;
            LL gc = gcd(FZ,FM);
            return fenshu{FZ/gc,FM/gc};
        }
    }a[11],b[11];
    
    int main(){
        //freopen("in.txt","r",stdin);
        LL T; scanf("%I64d",&T);
        for (LL n,cas=1;cas<=T;cas++){
            scanf("%I64d",&n);
            for (LL i=1;i<=n;i++) a[i].fz=1 ,b[i].fz=1;
            for (LL i=1;i<=n;i++) scanf("%I64d",&a[i].fz);
            for (LL i=1;i<=n;i++) scanf("%I64d",&b[i].fz);
            fenshu ans = fenshu(0,1);
            for (LL i=n;i>=1;i--){
                ans = b[i]/(ans + a[i]);
            }
            printf("Case #%I64d: %I64d %I64d
    ",cas,ans.fz,ans.fm);
        }
        return 0;
    }
    

    04

    #include <stdio.h>
    #include <iostream>
    
    using namespace std;
    int main(){
        int a[21]={0,0,0,0,1,1,2,3,3,4,5,6,7,7,8,9,10,11,12,13,14},T,t=1;
        cin >> T;
        while (T--){
            int n;
            cin >> n;
            cout << "Case #" << t++ << ": " << a[n] << endl;
        }
    }

    06

    #include <stdio.h>
    #include <iostream>
    #include <cstring>
    
    using namespace std;
    int main(){
        int a[10010]={},T,t=1;
        cin >> T;
        while (T--){
            int n,k,x=0;
            cin >> n >> k;
            memset(a,0,sizeof a);
            cout << "Case #" << t++ << ": ";
            for (int i=1;i<=k;i++) {
                printf("%d ",2*i);
                a[2*i]=1;
                x++;
            }
            for (int i=1;i<=n;i++){
                if (!a[i]){
                    x++; printf("%d",i);
                    if (x!=n) printf(" ");
                }
            }
            cout << endl;
        }
    }

    08
    KMP,
    next数组要改成Next数组,不然会CE
    还有每次要memset一下a,b数组的初值

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    const int N = 1000100;
    int a[N],b[N],Next[N];
    
    void getNext(int m){
        int i=0,j=-1;
        Next[0] = -1;
        for (;i<m;) {
            if (j==-1||b[i]==b[j]){
                if (b[++i]!=b[++j])Next[i]=j;
                else Next[i] = Next[j];
            }else j = Next[j];
        }
    }
    int KMP(int start,int n,int m,int p){
        int ans=0,i=start,j=0;
        for (;i<n&&j<m;){
            if (j==-1||a[i]==b[j])i+=p,j++;
            else j = Next[j];
            if (!i&&!j)break;
            if (j==m){
                ans++;
                j = Next[j];
            }
        }
        return ans;
    }
    
    int main(){
        //freopen("in.txt","r",stdin);
        int T,n,m,p;scanf("%d",&T);
        for (int cas=1;cas<=T;cas++){
            scanf("%d%d%d",&n,&m,&p);
            memset(Next,0,sizeof(Next));
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            for (int i=0;i<n;i++)scanf("%d",&a[i]);
            for (int i=0;i<m;i++)scanf("%d",&b[i]);
            int ans = 0;
            getNext(m);
            for (int i=0;i<p;i++) ans += KMP(i,n, m, p);
            printf("Case #%d: %d
    ",cas,ans);
        }
        return 0;
    }

    10
    每次取前半段的数字-1,然后构造回文数,
    每次可以减掉一半的位数,1000位很快就减完了
    涉及高精度减法,偷懒写java了,
    诶,java不熟,这辈子没写过这么丑的代码

    import java.math.*;
    //import java.io.*;
    import java.util.*;
    public class Main {
        public static BigInteger fanzhuan(BigInteger n){
            //System.out.println("fanzhuan" + n);
            int k = String.valueOf(n).length();
            BigInteger ret = BigInteger.ZERO;
            for (int i=1;i<=k;i++){
                ret = ret.add(n.mod(BigInteger.TEN));
                ret = ret.multiply(BigInteger.TEN);
                n = n.divide(BigInteger.TEN);
            }
            ret = ret.divide(BigInteger.TEN);
            return ret;
        }
        public static void main(String[] argv){
            Scanner cin = new Scanner(System.in);
            int T =cin.nextInt();
            for (int cas=1;cas<=T;cas++){
                BigInteger n = cin.nextBigInteger();
                int N = String.valueOf(n).length();
                int A = 0;
                BigInteger ans[] = new BigInteger[55];
                for (;N>1;){
                    //System.out.println("n=" + n);
                    BigInteger one0 = BigInteger.TEN.pow(N>>1);
                    BigInteger half = n.divide(one0);
                    if (N<=2){
                        if (N==1){ 
                            ans[++A] = n; 
                            n = BigInteger.ZERO;
                            break;
                        }else {//2 wei
                            if (n.compareTo(BigInteger.valueOf(19))==0){
                                ans[++A] = BigInteger.valueOf(11); 
                                ans[++A] = BigInteger.valueOf( 8); 
                                n = BigInteger.ZERO;
                                break;
                            }else if (n.compareTo(BigInteger.valueOf(19))==-1){
                                ans[++A] = BigInteger.valueOf(9);
                                ans[++A] = n.subtract(BigInteger.valueOf(9));
                                n = BigInteger.ZERO;
                                break;
                            }//else continue;
                        }
                    }
                    half = half.subtract(BigInteger.ONE);
                    //System.out.println("half=" + half);
                    BigInteger fan = fanzhuan(half);
                    if (N%2>0) fan = fan.mod(one0);
                    //System.out.println("fan=" + fan);
                    BigInteger jan = half.multiply(one0).add(fan);
                    //System.out.println("jan=" + jan);
                    ans[++A] = jan ;
                    n = n.subtract(jan);
                    N = String.valueOf(n).length();
                }
                if (n.compareTo(BigInteger.ZERO)==1)ans[++A] = n;
                System.out.printf("Case #%d:
    %d
    ",cas,A);
                for (int i=1;i<=A;i++){
                    System.out.println(ans[i]);
                }
            }
            cin.close();
        }
    }

    黑大帅5题铜,不知道大连的时候我们也没有这个好运气
    rp++

  • 相关阅读:
    Mac上TexStudio无法显示中文字符的问题
    python中import与from方法总结
    Jupter Notebook 使用技法
    python把列表(list)传给函数形参时的问题剖析
    Spyder常用快捷键
    用Tinkercad学arduino之 多喇叭发声
    用Tinkercad学arduino之 播放旋律
    用Tinkercad学arduino之 音调键盘 按键改变音调
    用Tinkercad学arduino之 伺服电机摆动
    用Tinkercad学arduino之 读取电位器模拟输入
  • 原文地址:https://www.cnblogs.com/cww97/p/7533969.html
Copyright © 2011-2022 走看看