• [BNU弱校联萌]背水一战


    比赛链接:http://acm.bnu.edu.cn/v3/contest_show.php?cid=6869

    A:字典序输出三个数的排列

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <iomanip>
     4 #include <cstring>
     5 #include <climits>
     6 #include <complex>
     7 #include <fstream>
     8 #include <cassert>
     9 #include <cstdio>
    10 #include <bitset>
    11 #include <vector>
    12 #include <deque>
    13 #include <queue>
    14 #include <stack>
    15 #include <ctime>
    16 #include <set>
    17 #include <map>
    18 #include <cmath>
    19 
    20 using namespace std;
    21 
    22 int a[3];
    23 
    24 int main() {
    25     // freopen("in", "r", stdin);
    26     int kase = 0;
    27     int T_T;
    28     scanf("%d", &T_T);
    29     while(T_T--) {
    30         scanf("%d %d %d", &a[0], &a[1], &a[2]);
    31         printf("Case #%d:
    ", ++kase);
    32         sort(a, a+3);
    33         if(a[0] == a[2]) {
    34             printf("%d %d %d
    ", a[0], a[0], a[0]);
    35         }
    36         else if(a[0] == a[1]) {
    37             printf("%d %d %d
    ", a[0], a[1], a[2]);
    38             printf("%d %d %d
    ", a[1], a[2], a[0]);
    39             printf("%d %d %d
    ", a[2], a[1], a[0]);
    40         }
    41         else if(a[1] == a[2]) {
    42             printf("%d %d %d
    ", a[0], a[1], a[2]);
    43             printf("%d %d %d
    ", a[1], a[0], a[2]);
    44             printf("%d %d %d
    ", a[2], a[1], a[0]);
    45         }
    46         else {
    47             printf("%d %d %d
    ", a[0], a[1], a[2]);
    48             printf("%d %d %d
    ", a[0], a[2], a[1]);
    49             printf("%d %d %d
    ", a[1], a[0], a[2]);
    50             printf("%d %d %d
    ", a[1], a[2], a[0]);
    51             printf("%d %d %d
    ", a[2], a[0], a[1]);
    52             printf("%d %d %d
    ", a[2], a[1], a[0]);
    53         }
    54     }
    55 }
    A

    C.小学数学的数的组合问题

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <iomanip>
     4 #include <cstring>
     5 #include <climits>
     6 #include <complex>
     7 #include <fstream>
     8 #include <cassert>
     9 #include <cstdio>
    10 #include <bitset>
    11 #include <vector>
    12 #include <deque>
    13 #include <queue>
    14 #include <stack>
    15 #include <ctime>
    16 #include <set>
    17 #include <map>
    18 #include <cmath>
    19 
    20 using namespace std;
    21 
    22 const int maxn = 100010;
    23 int n, m, q, x;
    24 
    25 int main() {
    26     // freopen("in", "r", stdin);
    27     int kase = 0;
    28     int T_T;
    29     scanf("%d", &T_T);
    30     while(T_T--) {
    31         scanf("%d %d %d", &n, &m, &q);
    32         printf("Case #%d:
    ", ++kase);
    33         for(int i = 0; i < q; i++) {
    34             scanf("%d", &x);
    35             if(x <= n && x < m) {
    36                 printf("%d
    ", x-1);
    37             }
    38             else if(x > n + m) {
    39                 printf("%d
    ", 0);
    40             }
    41             else if(x > n && x <= m){
    42                 printf("%d
    ", n);
    43             }
    44             else if(x <= n && x > m) {
    45                 printf("%d
    ", m);
    46             }
    47             else if(x > n && x > m) {
    48                 printf("%d
    ", n + m - x + 1);
    49             }
    50             else {
    51                 printf("%d
    ", x - 1);
    52             }
    53         }
    54     }
    55 }
    C

    K.判断四个点围成的图形是什么

      1 #include <algorithm>
      2 #include <iostream>
      3 #include <iomanip>
      4 #include <cstring>
      5 #include <climits>
      6 #include <complex>
      7 #include <fstream>
      8 #include <cassert>
      9 #include <cstdio>
     10 #include <bitset>
     11 #include <vector>
     12 #include <deque>
     13 #include <queue>
     14 #include <stack>
     15 #include <ctime>
     16 #include <set>
     17 #include <map>
     18 #include <cmath>
     19 
     20 using namespace std;
     21 
     22 typedef struct Point {
     23     int x;
     24     int y;
     25     friend bool operator ==(Point a, Point b) {
     26         return a.x == b.x && a.y == b.y;
     27     }
     28 };
     29 
     30 Point p[4];
     31 
     32 bool reapeat() {
     33     int i = 0, j;
     34     for(; i < 4; i++) {
     35         for(j = i+1; j < 4; j++) {
     36             if(p[i] == p[j]) {
     37                 break;
     38             }
     39         }
     40         if(j != 4) {
     41             break;
     42         }
     43     }
     44     return i != 4;
     45 }
     46 
     47 bool par() {
     48     int a = (p[1].y - p[0].y) * (p[3].x - p[2].x);
     49     int b = (p[1].x - p[0].x) * (p[3].y - p[2].y);
     50     int c = (p[2].x - p[1].x) * (p[3].y - p[0].y);
     51     int d = (p[3].x - p[0].x) * (p[2].y - p[1].y);
     52     if(a != b) {
     53         return false;
     54     }
     55     return c == d;
     56 }
     57 
     58 bool rec() {
     59     int a = (p[0].x - p[2].x) * (p[0].x - p[2].x) + (p[0].y - p[2].y) * (p[0].y - p[2].y);
     60     int b = (p[1].x - p[3].x) * (p[1].x - p[3].x) + (p[1].y - p[3].y) * (p[1].y - p[3].y);
     61     return a == b;
     62 }
     63 
     64 bool dia() {
     65     int a = (p[0].y - p[2].y) * (p[1].y - p[3].y);
     66     int b = (p[1].x - p[3].x) * (p[0].x - p[2].x);
     67     return a == -b;
     68 }
     69 
     70 int main() {
     71     // freopen("in", "r", stdin);
     72     int kase = 0;
     73     int T_T;
     74     scanf("%d", &T_T);
     75     while(T_T--) {
     76         printf("Case #%d: ", ++kase);
     77         for(int i = 0; i < 4; i++) {
     78             scanf("%d %d", &p[i].x, &p[i].y);
     79         }
     80         if(reapeat()) {
     81             printf("Others
    ");
     82         }
     83         else {
     84             if(par()) {
     85                 bool flag1 = rec();
     86                 bool flag2 = dia();
     87                 if(flag1 && flag2) {
     88                     printf("Square
    ");
     89                 }
     90                 else if(!flag1 && !flag2) {
     91                     printf("Parallelogram
    ");
     92                 }
     93                 else if(flag1) {
     94                     printf("Rectangle
    ");
     95                 }
     96                 else if(flag2) {
     97                     printf("Diamond
    ");
     98                 }
     99             }
    100             else {
    101                 printf("Others
    ");
    102             }
    103         }
    104     }
    105 }
    K

    A题新姿势:哈希去重

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <iomanip>
     4 #include <cstring>
     5 #include <climits>
     6 #include <complex>
     7 #include <fstream>
     8 #include <cassert>
     9 #include <cstdio>
    10 #include <bitset>
    11 #include <vector>
    12 #include <deque>
    13 #include <queue>
    14 #include <stack>
    15 #include <ctime>
    16 #include <set>
    17 #include <map>
    18 #include <cmath>
    19 
    20 using namespace std;
    21 
    22 const int maxn = 1000;
    23 typedef unsigned long long ull;
    24 const int B = 100007;
    25 int n;
    26 int vis[maxn];
    27 int ans[maxn];
    28 int num[maxn];
    29 set<ull> has;
    30 
    31 void solve1(int cur) {
    32     if(cur == n) {
    33         ull ah = 0;
    34         for(int i = 0; i < n; i++) {
    35             ah = ah * B + ans[i];
    36         }
    37         if(has.find(ah) == has.end()) {
    38             has.insert(ah);
    39             for(int i = 0; i < n; i++) {
    40                 printf("%d", ans[i]);
    41                 if(i < n-1) printf(" ");
    42                 else printf("
    ");
    43             }
    44         }
    45         return ;
    46     }
    47     for(int i = 0; i < n; i++) {
    48         if(!vis[i]) {
    49             vis[i] = 1;
    50             ans[cur] = num[i];
    51             solve1(cur + 1);
    52             vis[i] = 0;
    53         }
    54     }
    55 
    56 }
    57 
    58 int main() {
    59     // freopen("in", "r", stdin);
    60     int T_T;
    61     scanf("%d", &T_T);
    62     n = 3;
    63     for(int _ = 1; _ <= T_T; _++) {
    64         has.clear();
    65         scanf("%d %d %d", &num[0], &num[1], &num[2]);
    66         printf("Case #%d:
    ", _);
    67         memset(vis, 0, sizeof(vis));
    68         sort(num, num+n);
    69         solve1(0);
    70     }
    71 }
    A
  • 相关阅读:
    angularJS1遍历
    IDEA配置Tomcat
    IDEA配置JDK
    序列化
    servlet,filter,listener,intercepter区别
    textarea文本域值中含有大量 问题
    struts标签与jstl标签互换
    Struts/Hibernate/Spring源码下载
    捕获浏览器关闭、刷新事件,在窗体关闭时从全局对象里移除当前用户
    生成jsp验证码的代码详解(servlet版)
  • 原文地址:https://www.cnblogs.com/kirai/p/4858896.html
Copyright © 2020-2023  润新知