zoukankan      html  css  js  c++  java
  • 17-06-11模拟赛

    T1:按题意模拟计算即可。

    Code:

     1 #include<cstdio> 
     2 #include<cstring> 
     3 #include<algorithm> 
     4 using namespace std; 
     5 int n,x,p1,p2,p3,sum; 
     6 inline int in() 
     7 { 
     8     int x=0,f=1;char ch=getchar(); 
     9     while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();} 
    10     while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();} 
    11     return x*f; 
    12 } 
    13 int main () 
    14 { 
    15     n=in();x=in();sum=0; 
    16     for (int i=1;i<=n;++i){ 
    17         p1=in();p2=in(); 
    18         if (abs(p1-p2)<=x) sum+=max(p1,p2);else sum+=in(); 
    19     }printf("%d",sum);return 0; 
    20 }

    T2:将存款金额从大到小排序,而后从大到小算出至每个账户所对应的A值与B值,与最优值进行比较即可。

    Code:

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define ll long long
     5 #define MN 300005
     6 using namespace std;
     7 inline int in()
     8 {
     9     int x=0,f=1;char ch=getchar();
    10     while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    11     while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    12     return x*f;
    13 }
    14 inline bool cmp(int a,int b){return a>b;}
    15 ll sum[MN],tot;
    16 int a[MN],n,curi;
    17 int main ()
    18 {
    19     n=in();for (int i=1;i<=n;++i) a[i]=in(),tot+=a[i];
    20     sort(a+1,a+n+1,cmp);sum[0]=0;curi=0;
    21     for (int i=1;i<=n;++i){
    22         sum[i]=sum[i-1]+a[i];
    23         if (sum[i]*n-tot*i>sum[curi]*n-tot*curi) curi=i;
    24     }
    25     double A=(double)100.0*curi/n,B=(double)100.0*sum[curi]/tot;
    26     printf("%.6lf
    %.6lf",A,B);return 0;
    27 }

    T3:按宽度从大到小排序,若有比当前最高高度更高的矩形,则总面积加上该矩形的宽与 该矩形的高与当前最高高度的差 的积。

    Code:

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define ll long long
     5 using namespace std;
     6 inline int in()
     7 {
     8     int x=0,f=1;char ch=getchar();
     9     while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    10     while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    11     return x*f;
    12 }
    13 struct rect{
    14     int x,y;
    15 }a[1000005];
    16 inline bool cmp(rect a,rect b){return (a.x==b.x)?a.y>b.y:a.x>b.x;} 
    17 ll ans;
    18 int n,cury;
    19 int main ()
    20 {
    21     n=in();for (int i=1;i<=n;++i) a[i].x=in(),a[i].y=in();
    22     sort(a+1,a+n+1,cmp);cury=0;ans=0;
    23     for (int i=1;i<=n;++i){
    24         if (a[i].y>cury) 
    25         ans+=1ll*a[i].x*(a[i].y-cury),cury=a[i].y;
    26     }printf("%lld",ans);
    27     return 0;
    28 }

    T4:任取一点作为起点,对于没有与其连边的点进行一次操作,统计是否所有点间都连边。若有两点间无连边,则为NE。

    对于该点进行一次操作,对于没有与其连边的点进行一次操作,统计是否所有点间都连边。若有两点间无连边,则为NE,否则为DA。

    Code:

     1 #include<cstdio> 
     2 #include<cstring> 
     3 #include<algorithm> 
     4 #define MN 1002 
     5 using namespace std; 
     6 inline int in() 
     7 { 
     8     int x=0,f=1;char ch=getchar(); 
     9     while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();} 
    10     while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();} 
    11     return x*f; 
    12 } 
    13 bool t[MN][MN],mp[MN][MN]; 
    14 int n,m,x,y; 
    15 inline void change(int x){ 
    16     for (int i=1;i<=n;++i) t[x][i]^=1,t[i][x]^=1; 
    17 } 
    18 inline bool dfs(int x){ 
    19     for (int i=1;i<=n;++i) if (x!=i&&!t[x][i]) change(i); 
    20     for (int i=1;i<=n;++i) 
    21     for (int j=1;j<=n;++j) if (i!=j&&!t[i][j]) return 0;return 1; 
    22 } 
    23 int main () 
    24 { 
    25     n=in();m=in();memset(mp,0,sizeof(mp)); 
    26     for (int i=1;i<=m;++i){ 
    27         x=in();y=in(); 
    28         mp[x][y]=mp[y][x]=1; 
    29     }memcpy(t,mp,sizeof(mp));if (!dfs(1)){printf("NE");return 0;} 
    30     memcpy(t,mp,sizeof(mp));change(1);printf(dfs(1)?"DA":"NE");return 0; 
    31 }
  • 相关阅读:
    VS 2008潜在强大的功能:提取EXE文件中的ICO等资源
    园友们注意:淘宝网上QQ会员 4钻 3元 等都为骗子行为
    Comet Async Process Request Handler
    WCF(Sender) to MSMQ to WCF(Receiver)
    ASP.NET Web Form GridView DetailsView Query Edit
    WCF NetTcp AsyncQueue Service
    Xml CDATA 序列化
    Sync Invoke Remoting Async Invoke
    .Net 4.0 Remoting ConcurrentQueue
    Socket Async Receive Data to LinkedList Buffer (telnet proxy server)
  • 原文地址:https://www.cnblogs.com/codingutopia/p/test170611.html
Copyright © 2011-2022 走看看