BUPT 2014新生暑假个人排位赛01

来源:互联网 发布:老鼠仓软件 编辑:程序博客网 时间:2024/05/29 04:47


A.学姐的桌面

话说这题的题面真是有意思

#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>#include <cassert>#include <cstdio>#include <bitset>#include <vector>#include <deque>#include <queue>#include <stack>#include <ctime>#include <set>#include <map>#include <cmath> using namespace std;  template<class T>inline bool read(T &n){    T x = 0, tmp = 1; char c = getchar();    while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();    if(c == EOF) return false;    if(c == '-') c = getchar(), tmp = -1;    while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar();    n = x*tmp;    return true;} const int MAXN=100010;int n;int a[MAXN]; int main(){    int T,s;    read(T);    while(T--)    {        read(n);read(s);        int sum=0;        for(int i=0;i<n;i++)        {            read(a[i]);            if(a[i]<s)                sum++;        }        double ans=100.0*sum;        ans/=(double)n;        printf("%.2f%%\n",ans);    }    return 0;}


B.学姐去学车

这题的题面也很有意思......真是容易让人看不懂啊

[1,n]:教练一 [n+1,n+m+1]:教练二

 [n+m+2,2n+1]:教练一  [2n+2,2n+m+2]:教练二


#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>#include <cassert>#include <cstdio>#include <bitset>#include <vector>#include <deque>#include <queue>#include <stack>#include <ctime>#include <set>#include <map>#include <cmath> using namespace std;  template<class T>inline bool read(T &n){    T x = 0, tmp = 1; char c = getchar();    while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();    if(c == EOF) return false;    if(c == '-') c = getchar(), tmp = -1;    while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar();    n = x*tmp;    return true;}//------------------------------------------------------------------- int n,m,q;  int main(){    int T;    read(T);    while(T--)    {        read(n);read(m);        int sum=m+n,temp;        read(q);        while(q--)        {            read(temp);            if(temp<=n)                printf("1\n");            else if(temp<n+m)                printf("2\n");            else            {                temp%=n+1;                if(temp<m)                    printf("2\n");                else                    printf("1\n");            }        }    }    return 0;}


C.学姐的学弟

暴搜,计算几何也可以......

#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>#include <cassert>#include <cstdio>#include <bitset>#include <vector>#include <deque>#include <queue>#include <stack>#include <ctime>#include <set>#include <map>#include <cmath>using namespace std;template<class T>inline bool read(T &n){    T x = 0, tmp = 1; char c = getchar();    while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();    if(c == EOF) return false;    if(c == '-') c = getchar(), tmp = -1;    while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar();    n = x*tmp;    return true;}//-------------------------------------------------------------------const int MAXN=110;const double PI=acos(-1.0);const double sqr3=sqrt(3.0);int mapp[MAXN][MAXN];double ans=0.0;void check(int x,int y){bool a=false,b=false,c=false,d=false;int num=0;if(mapp[x][y])a=!a,num++;if(mapp[x][y+1])b=!b,num++;if(mapp[x+1][y+1])d=!d,num++;if(mapp[x+1][y])c=!c,num++;if(num>=3)ans+=1;else if(num==1)ans+=PI/4;else if(num==2){if(a&&d&&!b&&!c||!a&&!d&&b&&c)ans+=1;else if(!a&&d&&b&&!c||a&&!d&&b&&!c||!a&&d&&!b&&c||a&&!d&&!b&&c)ans+=PI/6+sqr3/4;}}int main(){//freopen("data.txt","r",stdin);int T,n;read(T);while(T--){ans=0.0;memset(mapp,0,sizeof(mapp));read(n);for(int i=0;i<n;i++){int x,y;read(x);read(y);mapp[x][y]++;}for(int i=0;i<=100;i++)for(int j=0;j<=100;j++)check(i,j);printf("%.5f\n",ans);}} 


D.BLOCK

暴搜,bfs+剪枝,bfs

我用的是暴搜,计算四个方格里是否存在三个#的情况,此情况并有非矩形的存在

以矩形的右下角作为计数,记录矩形个数。

#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>#include <cassert>#include <cstdio>#include <bitset>#include <vector>#include <deque>#include <queue>#include <stack>#include <ctime>#include <set>#include <map>#include <cmath> using namespace std; template<class T>inline bool read(T &n){    T x = 0, tmp = 1; char c = getchar();    while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();    if(c == EOF) return false;    if(c == '-') c = getchar(), tmp = -1;    while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar();    n = x*tmp;    return true;} //------------------------------------------------------------------- char mapp[1010][1010];int n,m,ans=0;int ok=true; void check(int x,int y){    bool a=false,b=false,c=false,d=false;    int num=0;    if(mapp[x][y]=='#')        a=!a,num++;    if(mapp[x][y+1]=='#')        b=!b,num++;    if(mapp[x+1][y+1]=='#')        d=!d,num++;    if(mapp[x+1][y]=='#')        c=!c,num++;    if(num==3)        ok=false;    else if(num==1&&a)        ans++;    else if(num==2&&a&&d)        ans++;         } int main(){//  freopen("data.txt","r",stdin);    while(read(n) && read(m))    {        ans=0;ok=true;        for(int i=0;i<n;i++)            gets(mapp[i]);        for(int i=0;i<n&&ok;i++)            for(int j=0;j<m&&ok;j++)                check(i,j);        if(!ok)            puts("So Sad");        else            printf("There are %d ships.\n",ans);    }}


E.数的关系

组合数学

离线DP得出答案再计算,用高精度

没有写JAVA的码

#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>#include <cassert>#include <cstdio>#include <bitset>#include <vector>#include <deque>#include <queue>#include <stack>#include <ctime>#include <set>#include <map>#include <cmath> using namespace std; void add(char a[],char b[],char back[]){    int i,j,k,up,x,y,z,l;    char *c;    if(strlen(a) > strlen(b))        l = strlen(a)+2;    else        l = strlen(b)+2;    c = (char*)malloc(l*sizeof(char));    i = strlen(a)-1;    j = strlen(b)-1;    k = 0;    up = 0;    while(j>=0 || i>=0)    {        if(i<0) x = '0';        else            x = a[i];        if(j<0) y = '0';        else            y = b[j];        z = x-'0'+y-'0';        if(up)            z++;        if(z>9)        {            up = 1;            z%=10;        }        else            up = 0;        c[k++] = z+'0';        i--;        j--;    }    if(up)        c[k++] = '1';    i = 0;    c[k] = '\0';    for(k-=1; k>=0; k--)        back[i++] = c[k];    back[i] = '\0';} //大数乘以小数 void mult(char c[],int m,char t[]){    char s[1000];    int len=strlen(c);    for(int i=0; i<len; i++)        s[len-i-1]=c[i]-'0';    int flag,add=0;    for(int i=0; i<len; i++)    {        int k=s[i]*m+add;        if(k>=10)        {            s[i]=k%10;            add=k/10;            flag=1;        }        else        {            s[i]=k;            add=0;            flag=0;        }    }    while(add)    {        s[len++]=add%10;        add/=10;    }    for(int i=0; i<len; i++)        t[len-1-i]=s[i]+'0';    t[len]='\0';} //大数加小数void addt(char a[],int b,char c[]){    int len=strlen(a);    char s[1000];    for(int i=0; i<len; i++)        s[len-i-1]=a[i]-'0';    int add=0;    for(int i=0;; i++)    {        if(i>=len)        {            s[i]=0;            len++;        }        int k=s[i]+b%10+add;        b/=10;        if(k>=10)        {            s[i]=k%10;            add=k/10;        }        else        {            s[i]=k;            add=0;        }        if(b==0&&add==0)break;    }    for(int i=0; i<len; i++)        c[len-1-i]=s[i]+'0';    c[len]='\0'; } int n;char dp[110][110][1000],t1[1000],t2[1000],ans[110][1000]; int main(){    memset(dp,0,sizeof(dp));    memset(ans,0,sizeof(ans));    memset(t1,0,sizeof(t1));    memset(t2,0,sizeof(t2));    dp[1][1][0]='1';dp[1][1][1]='\0';    for(int i=1;i<=100;i++)    {        for(int j=1;j<=i;j++)        {//   cout<<i<<" "<<j<<endl;            mult(dp[i][j],j,t1);//cout<<t1<<endl;            add(dp[i+1][j],t1,t2);//cout<<t2<<endl;            strcpy(dp[i+1][j],t2);            mult(dp[i][j],j+1,t1);//cout<<t1<<endl;            add(dp[i+1][j+1],t1,t2);//cout<<t2<<endl;            strcpy(dp[i+1][j+1],t2);        }    }    for(int i=1;i<=100;i++)    {        for(int j=1;j<=i;j++)        {            add(ans[i],dp[i][j],t1);            strcpy(ans[i],t1);        }    }    while(scanf("%d",&n)!= EOF)    {        puts(ans[n]);    }    return 0;}


JAVA版


import java.awt.*;import java.util .*;import  java.io.*;import java.math.*;             public class Main{         public static void main (String[] args)    {          Scanner cin = new Scanner(System.in);        int n;        BigInteger dp[][]=new BigInteger[110][110];        BigInteger ans[]=new BigInteger[110];        for(int i=1;i<=101;i++)            for(int j=1;j<=101;j++)                dp[i][j]=new BigInteger("0");//      for(int i=1;i<=101;i++)//           for(int j=1;j<=i;j++)//                dp[i][j]=BigInteger.ZERO;        dp[1][1]=BigInteger.ONE;        for(int i=1;i<=100;i++)            for(int j=1;j<=i;j++)            {                dp[i+1][j]=dp[i+1][j].add(dp[i][j].multiply(BigInteger.valueOf(j)));                dp[i+1][j+1]=dp[i+1][j+1].add(dp[i][j].multiply(BigInteger.valueOf(j+1)));            }        for(int i=1;i<=100;i++)            ans[i]=new BigInteger("0");        for(int i=1;i<=100;i++)            for(int j=1;j<=i;j++)                ans[i]=ans[i].add(dp[i][j]);        while(cin.hasNext())        {            n=cin.nextInt();            System.out.println(ans[n]);        }        cin.close();    } //  private static BigInteger BigInteger(int j) {        // TODO Auto-generated method stub//      return null;//  }}




0 0