zoukankan      html  css  js  c++  java
  • SDUT_基础算法

    1001  即 hdu 2527  迷瘴

    太水了,快排+判断

    View Code
     1 #include<stdio.h>
    2 #include<algorithm>
    3 using namespace std;
    4 int main()
    5 {
    6 int n;
    7 scanf("%d",&n);
    8 while(n--)
    9 {
    10 int m,v,i;
    11 double w,pi=0;
    12 scanf("%d%d%lf",&m,&v,&w);
    13 double num[1005];
    14 for( i=0;i<m;i++)
    15 scanf("%lf",&num[i]);
    16 sort(num,num+m);
    17
    18 for( i=0;i<m;i++)
    19 {
    20 double t=(pi+num[i])/(i+1);
    21
    22 if(t<=w) pi+=num[i];
    23 else break;
    24 }
    25 // if(i==m) i=m-1;
    26 if(i<=0) puts("0 0.00");
    27 else
    28 printf("%d %.2f\n",i*v,pi/(i*100));
    29 }
    30
    31 }

    1002   即  hdu 1097  A hard puzzle

    数论的题:二分+快速幂取模

    队长推荐的解法

    View Code
     1 #include<stdio.h>
    2 __int64 num_mod(__int64 a,__int64 n)
    3 {
    4 if(n==0) return 1%10;
    5 if(n==1) return a%10;
    6 int t=num_mod(a,n/2);
    7 __int64 sum=t*t%10;
    8 if(n%2==1) sum=sum*a%10;
    9 return sum;
    10 }
    11 int main()
    12 {
    13 __int64 a,n;
    14 while(~scanf("%I64d%I64d",&a,&n))
    15 {
    16 printf("%I64d\n",num_mod(a,n));
    17 }
    18 return 0;
    19 }

    1003   即 hdu  1028  Ignatius and the Princess III

    dp  ,以前做过类似的题 ural 上的一个,关键还是状态转移方程

    map[n][i]=map[n-1][i-1]+map[n-i][i]------i表示分成的几份

    View Code
    #include<stdio.h>
    int map[125][125];
    int main()
    {
    int n;
    while(~scanf("%d",&n))
    {
    for(int i=1;i<=n;i++)
    {
    map[1][i]=0;
    map[i][1]=1;
    }
    int sum=0;
    for(int i=1;i<=n;i++)
    {
    for(int j=2;j<=i;j++)
    map[i][j]=map[i-1][j-1]+map[i-j][j];
    }
    for(int i=1;i<=n;i++)
    sum+=map[n][i];
    printf("%d\n",sum);
    }
    return 0;
    }

    1004  即 hdu   1598  find the most comfortable road

    自己dfs 写的结果wa ,两个城市之间可能有不止一条路

    然后 搜的解题报告 并查集+快排

    表示并查集弱爆了,最后还是vongang 帮我检查出的错误

    View Code
    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    const int inf=0x7ffffff;
    struct node
    {
    int s,e,w;
    }road[1005];
    int xx[205];
    int cmp(node a,node b)
    {
    return a.w<b.w;
    }
    int find(int x)
    {
    while(x!=xx[x]) x=xx[x];

    return x;
    }
    int main()
    {
    int n,m,j;
    while(~scanf("%d%d",&n,&m))
    {
    for(int i=0;i<m;i++)
    {
    scanf("%d%d%d",&road[i].s,&road[i].e,&road[i].w);

    }
    sort(road,road+m,cmp);
    int q; scanf("%d",&q);

    while(q--)
    {
    int a,b,sum=inf;
    scanf("%d%d",&a,&b);

    for(int i=0;i<m;i++)
    {
    for(j=0;j<=n;j++)
    xx[j]=j;
    for(j=i;j<m;j++)
    {
    int A,B;
    A=find(road[j].s);
    B=find(road[j].e);
    if(A!=B) xx[B]=A;
    if(find(a)==find(b))
    {
    int t=road[j].w-road[i].w;
    if(t<sum) sum=t;
    break;
    }
    }
    if(j==m) break;
    }
    if(sum==inf) puts("-1");
    else printf("%d\n",sum);
    }
    }
    return 0;
    }









    Just a little, maybe change the world
  • 相关阅读:
    PHP中pack、unpack的详细用法
    Rbac
    composer
    tp5+workman
    apache
    Vs2005安装后没有模板的解决方法
    java中使用mysqldump 备份数据库
    java中文件上传下载将file转为MultipartFile
    hibernate中的schema
    Java之 1.8新特性
  • 原文地址:https://www.cnblogs.com/skyming/p/2263674.html
Copyright © 2011-2022 走看看