2017 ACM ICPC Asia Shenyang Regional Contest

 

I Java大数

import java.math.*;
import java.util.*;

public class Main {

//    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T=in.nextInt();
        while(T--!=0)
        {
            BigInteger a=in.nextBigInteger();
            BigInteger b=in.nextBigInteger();
            BigInteger c=in.nextBigInteger();
            BigInteger d=in.nextBigInteger();
            System.out.println(a.add(b.add(c.add(d))));
        }
    }
}
View Code

F 找规律 得 面积sqrt(3b2-12)为整数,打表找规律得f[n]=4f[n-1]-f[n-2]

//package Demo;

import java.math.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {

        BigInteger[] a= new BigInteger[1005];
        a[1]=new BigInteger("4");
        a[2]=new BigInteger("14");
        a[3]=new BigInteger("52");
        for(int i=4;i<=100;i++)
        {
            a[i]=a[i-1].multiply(new BigInteger("4")).subtract(a[i-2]);
//            System.out.println(a[i]);
        }
        Scanner sc = new Scanner(System.in);
        int T;
        T=sc.nextInt();                
        while(T--!=0)
        {
            BigInteger n=sc.nextBigInteger();
            for(int i=1;i<=100;i++)
            {
                if(a[i].compareTo(n)>=0) {
                    System.out.println(a[i]);
                    break;
                }
            }
        }
    }

}
View Code

 

K 签到

#include<bits/stdc++.h>
using namespace std;

int a[505];
int c[505];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        for(int i=1; i<=n; i++)
            scanf("%d",&a[i]);
        int ans=0;
        for(int i=1;i<=n-1;i++)
            c[i]=a[i+1]-a[i]-1;
        ans=max(c[1],c[n-1]);
        for(int i=2;i<=n-2;i++)
            ans+=c[i];
        printf("%d\n",ans);
    }
}
View Code

 

L 思维

#include<bits/stdc++.h>
using namespace std;

const int maxn=2e5+10;
int head[maxn],ver[maxn*2],nxt[2*maxn];
int tot;
int ans=0;
int size[maxn];
int n,k;
void add(int x,int y)
{
    ver[++tot]=y;
    nxt[tot]=head[x];
    head[x]=tot;
}

void dfs(int x,int fa)
{
    size[x]=1;
    for(int i=head[x]; i; i=nxt[i])
    {
        int y=ver[i];
        if(fa==y) continue;
        dfs(y,x);
        size[x]+=size[y];
        if(size[y]>=k&&(n-size[y])>=k)
        {
            ans++;
//            printf("size%d=%d \n",x,size[x]);
        }
    }
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&k);
        for(int i=1; i<=n; i++)
        {
            head[i]=0;
            size[i]=0;
        }
        tot=0,ans=0;
        for(int i=1; i<=n-1; i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            add(x,y);
            add(y,x);
        }
        dfs(1,0);
        printf("%d\n",ans);
    }
}
View Code

 

posted @ 2019-10-16 16:02  paranoid。  阅读(206)  评论(0编辑  收藏  举报