• Codeforces Round #194 (Div. 2) 部分题解


    A: 题意:把n*n 个数 分成 n组,每组的总和都一样

    解法:比如n等于4,然后可以得到个矩阵    1    2    3    4

                                                            5    6    7    8

                                                            9    10   11   12

                                                           13    14   15   16

         你要分成n组和相同的, 每组里面必须从原来里每行取个最大的,第二大的,第三大的,第四大的

       

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     int n,k;
    11     scanf("%d",&n);
    12     for(int i = 0; i < n; i++) //输出 n 行 
    13     {
    14         k = 0;
    15         for(int j = i; j < n+i; j++) //每行输出n个数 
    16         {
    17             printf("%d ",j%n+1+n*k);
    18             k++;
    19         }
    20         printf("
    ");
    21     }
    22     return 0;
    23  } 
    View Code

    B:题意:给你八个点,构成1个矩形,x1<x2<x3,y1<y2<y3这三种类型,(x2,y2)不在矩形里 ,注意判重。。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 struct node
     9 {
    10     int x;
    11     int y;
    12 }a[10];
    13 
    14 int b1[10],b2[10];
    15 
    16 bool cmp1(node m,node n)
    17 {
    18     return m.x < n.x;
    19 }
    20 
    21 bool cmp2(node m,node n)
    22 {
    23     return m.y < n.y;
    24 }
    25 
    26 int main()
    27 {
    28     memset(b1,0,sizeof(b1));
    29     memset(b2,0,sizeof(b2));
    30     for(int i=0; i<8; i++)
    31     cin>>a[i].x>>a[i].y;
    32     sort(a,a+8,cmp1);
    33     for(int i=0; i<8; i++)
    34     for(int j=i+1; j<8; j++)
    35     {
    36         if(a[i].x==a[j].x && a[i].y==a[j].y)
    37         {
    38             printf("ugly
    ");
    39             return 0;
    40         }
    41     }
    42     int cnt=0,co=1;
    43     for(int i=1; i<8; i++)
    44     {
    45         if(a[i].x != a[i-1].x)
    46         {
    47             cnt++;
    48             b1[cnt] = co;
    49             co = 1;
    50         }
    51         else co++;
    52     }
    53     if(a[6].x == a[7].x) 
    54     {
    55         b1[++cnt] = co;
    56     } 
    57     sort(a,a+8,cmp2);
    58     co = 1;
    59     cnt = 0;
    60     for(int i=1; i<8; i++)
    61     {
    62         if(a[i].y != a[i-1].y)
    63         {
    64             cnt++;
    65             b2[cnt] = co;
    66             co = 0;
    67         }
    68         co++;
    69     }
    70     if(a[6].y == a[7].y) 
    71     {
    72         b2[++cnt] = co;
    73     } 
    74     int flag1=0,flag2=0;
    75     if(b1[1]==3&&b1[2]==2&&b1[3]==3) flag1 = 1;
    76     if(b2[1]==3&&b2[2]==2&&b2[3]==3) flag2 = 1;
    77     if(flag1&&flag2) printf("respectable
    ");
    78     else printf("ugly
    ");
    79     return 0;
    80 }
    View Code

    C题意: 用面值为3的次幂的硬币 购买价值为n的商品 , 要求硬币总价值>n且硬币数最多

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 using namespace std;
     7 __int64 n;
     8 int main()
     9 {
    10     while(scanf("%I64d",&n)!=EOF)
    11     {
    12         while(n%3==0)n/=3;
    13         printf("%I64d
    ",((n+2)/3));
    14     }
    15     return 0;
    16 }
    View Code
  • 相关阅读:
    SDSF output to PS
    3亿人出走后的中国农村,路在何方?
    oracle function
    C8051特点
    c8051单片机注意事项:
    一个因xdata声明引起的隐含错误
    宏 函数 内联函数inline
    字符串与液晶显示的一个问题
    XON/OFF
    excel之实验数据处理线性拟合
  • 原文地址:https://www.cnblogs.com/ar940507/p/3221910.html
Copyright © 2020-2023  润新知