zoukankan      html  css  js  c++  java
  • Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only)

    http://codeforces.com/contest/90

    A

     1 #include<iostream>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define maxn 100005
     7 typedef long long ll;
     8 typedef unsigned long long ull;
     9 const ull MOD=257;
    10 /*#ifndef ONLINE_JUDGE
    11         freopen("1.txt","r",stdin);
    12 #endif */
    13 
    14 int num1(int n){return (n/2)+(n%2);}
    15 
    16 int main(){
    17     #ifndef ONLINE_JUDGE
    18      //   freopen("1.txt","r",stdin);
    19     #endif
    20     std::ios::sync_with_stdio(false);
    21     int r,g,b;
    22     cin>>r>>g>>b;
    23     int ans=max(num1(r)*3-3+30,max(num1(g)*3-2+30,num1(b)*3-1+30));
    24     cout<<ans<<endl;
    25 }
    View Code

    B

     1 #include<iostream>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define maxn 100005
     7 typedef long long ll;
     8 typedef unsigned long long ull;
     9 const ull MOD=257;
    10 /*#ifndef ONLINE_JUDGE
    11         freopen("1.txt","r",stdin);
    12 #endif */
    13 
    14 int n,m;
    15 string s[105];
    16 int book[105][105];
    17 
    18 int main(){
    19     #ifndef ONLINE_JUDGE
    20      //   freopen("1.txt","r",stdin);
    21     #endif
    22     std::ios::sync_with_stdio(false);
    23     cin>>n>>m;
    24     for(int i=0;i<n;i++) cin>>s[i];
    25     for(int i=0;i<n;i++){
    26         for(int j=0;j<m;j++){
    27             for(int k=i+1;k<n;k++){
    28                 if(s[i][j]==s[k][j]) book[k][j]=1,book[i][j]=1;
    29             }
    30             for(int k=j+1;k<m;k++){
    31                 if(s[i][j]==s[i][k]) book[i][k]=1,book[i][j]=1;
    32             }
    33         }
    34     }
    35     for(int i=0;i<n;i++){
    36         for(int j=0;j<m;j++){
    37             if(book[i][j]==0) cout<<s[i][j];
    38         }
    39     }
    40 }
    View Code

    C

     1 #include<iostream>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define maxn 100005
     7 typedef long long ll;
     8 typedef unsigned long long ull;
     9 const ull MOD=257;
    10 /*#ifndef ONLINE_JUDGE
    11         freopen("1.txt","r",stdin);
    12 #endif */
    13 
    14 int n,m,k;
    15 long long a;
    16 
    17 int main(){
    18     #ifndef ONLINE_JUDGE
    19      //   freopen("1.txt","r",stdin);
    20     #endif
    21     std::ios::sync_with_stdio(false);
    22     cin>>n>>m>>k;
    23     ll tmp=100005;
    24     for(int i=1;i<=n;i++){
    25         cin>>a;
    26         if(tmp>a&&((i%2)==1)){
    27             tmp=a;
    28         }
    29     }
    30     ll ans=0,x=n/2+1;
    31     if((n%2)&&(x<=m)){
    32         ans=m/x*k;
    33         ans=min(ans,tmp);
    34     }
    35     cout<<ans<<endl;
    36 }
    View Code

    D

    大模拟

      1 #include<bits/stdc++.h>
      2 using namespace std;
      3 #define lson l,mid,rt<<1
      4 #define rson mid+1,r,rt<<1|1
      5 #define sqr(x) ((x)*(x))
      6 typedef long long ll;
      7 typedef unsigned long long ull;
      8 const ull MOD=257;
      9 /*#ifndef ONLINE_JUDGE
     10         freopen("1.txt","r",stdin);
     11 #endif */
     12 
     13 const int maxn = 200;
     14 const int max_len = 200;
     15 
     16 struct widget;
     17 
     18 struct Box{
     19     string name;
     20     long long x, y;
     21     vector<Box * > box_inside;
     22     vector<widget *> widget_inside;
     23     long long border, space;
     24     // type = true if Box = HBox
     25     bool type;
     26     vector<Box *> parent;
     27 
     28     void init(const string s, const bool t){
     29         //printf("init box name = %s type = %d
    ", s.c_str(), t);
     30         //fflush(stdout);
     31 
     32         name = s;
     33         x = y = 0;
     34         border = space = 0;
     35         type = t;
     36     }
     37 
     38     void update();
     39 
     40     void pack(Box * new_parent){
     41         parent.push_back(new_parent);
     42         new_parent->box_inside.push_back(this);
     43         (*new_parent).update();
     44     }
     45 
     46     void set_space(const int new_space){
     47         space = new_space;
     48         update();
     49     }
     50 
     51     void set_border(const int new_border){
     52         border = new_border;
     53         update();
     54     }
     55 
     56 };
     57 
     58 
     59 struct widget{
     60     string name;
     61     long long x, y;
     62 
     63     void pack(Box * new_parent){
     64         new_parent->widget_inside.push_back(this);
     65         (*new_parent).update();
     66     }
     67 
     68     void init(const string s, const int x1, const int y1){
     69         name = s;
     70         x = x1;
     71         y = y1;
     72     }
     73 };
     74 
     75 void Box::update(){
     76     //printf("trying to update %s type = %d
    ", name.c_str(), type);
     77     //fflush(stdout);
     78 
     79     if (type){
     80         x = 0;
     81         y = 0;
     82 
     83         for(size_t i = 0; i < box_inside.size(); ++i){
     84             x += box_inside[i]->x;
     85             y = max(y, box_inside[i]->y);
     86         }
     87 
     88 
     89         for(size_t i = 0; i < widget_inside.size(); ++i){
     90             x += widget_inside[i]->x;
     91             y = max(y, widget_inside[i]->y);
     92         }
     93         if (widget_inside.size() + box_inside.size() != 0){
     94             x += 2 * border + (box_inside.size() + widget_inside.size() - 1) * space;
     95             y += 2 * border;
     96         }
     97     }
     98     else{
     99         x = 0;
    100         y = 0;
    101 
    102         for(size_t i = 0; i < box_inside.size(); ++i){
    103             y += box_inside[i]->y;
    104             x = max(x, box_inside[i]->x);
    105         }
    106 
    107         for(size_t i = 0; i < widget_inside.size(); ++i){
    108             y += widget_inside[i]->y;
    109             x = max(x, widget_inside[i]->x);
    110         }
    111 
    112         if (widget_inside.size() + box_inside.size() != 0){
    113             y += 2 * border + (box_inside.size() + widget_inside.size() - 1) * space;
    114             x += 2 * border;
    115         }
    116     }
    117 
    118     for(size_t i = 0; i < parent.size(); ++i)
    119         (*parent[i]).update();
    120 }
    121 
    122 
    123 struct res{
    124     string name;
    125     long long x, y;
    126 };
    127 
    128 bool comp(const res a, const res b){
    129     if (a.name < b.name)
    130         return 1;
    131     else
    132         return 0;
    133 }
    134 
    135 
    136 Box ar_of_box[maxn];
    137 widget ar_of_widget[maxn];
    138 int n, last_b, last_w;
    139 
    140 char buf[max_len];
    141 string s;
    142 
    143 res res_ar[maxn];
    144 
    145 
    146 int main(){
    147     #ifndef ONLINE_JUDGE
    148        // freopen("1.txt","r",stdin);
    149     #endif
    150     last_b = last_w = 0;
    151     scanf("%d
    ", &n);
    152     for(int i = 0; i < n; ++i){
    153         cin.getline(buf,200);
    154         s = buf;
    155         if (s.substr(0, 4) == "VBox")
    156             ar_of_box[last_b++].init(s.substr(5, s.size() - 5), false);
    157 
    158         if (s.substr(0, 4) == "HBox")
    159             ar_of_box[last_b++].init(s.substr(5, s.size() - 5), true);
    160 
    161         if (s.substr(0, 6) == "Widget"){
    162             int x, y;
    163             x = y = 0;
    164             s.erase(0, 7);
    165             string name = "";
    166             int k = 0;
    167 
    168             while (s[k] != '('){
    169                 name += s[k];
    170                 ++k;
    171             }
    172 
    173             ++k;
    174 
    175             while (s[k] >= '0' && s[k] <= '9'){
    176                 x = x * 10 + s[k] - '0';
    177                 ++k;
    178             }
    179 
    180             ++k;
    181 
    182             while (s[k] >= '0' && s[k] <= '9'){
    183                 y = y * 10 + s[k] - '0';
    184                 ++k;
    185             }
    186 
    187             ar_of_widget[last_w++].init(name, x, y);
    188         }
    189 
    190         if (s.find(".pack") != s.npos){
    191             string name1, name2;
    192             name1 = name2 = "";
    193 
    194             int k = 0;
    195             while (s[k] != '.'){
    196                 name1 += s[k];
    197                 ++k;
    198             }
    199 
    200             while (s[k] != '(')
    201                 ++k;
    202             ++k;
    203 
    204             while (s[k] != ')'){
    205                 name2 += s[k];
    206                 ++k;
    207             }
    208 
    209             Box * parent = NULL;
    210             for(int j = 0; j < last_b; ++j)
    211                 if (name1 == ar_of_box[j].name)
    212                     parent = &ar_of_box[j];
    213 
    214             for(int j = 0; j < last_b; ++j)
    215                 if (name2 == ar_of_box[j].name)
    216                     ar_of_box[j].pack(parent);
    217 
    218             for(int j = 0; j < last_w; ++j)
    219                 if (name2 == ar_of_widget[j].name)
    220                     ar_of_widget[j].pack(parent);
    221         }
    222 
    223         if (s.find(".set_border") != s.npos){
    224             string name = "";
    225             int k = 0;
    226             int border = 0;
    227 
    228             while (s[k] != '.'){
    229                 name += s[k];
    230                 ++k;
    231             }
    232 
    233             while (s[k] != '(')
    234                 ++k;
    235             ++k;
    236 
    237             while (s[k] >= '0' && s[k] <= '9'){
    238                 border = border * 10 + s[k] - '0';
    239                 ++k;
    240             }
    241 
    242             for(int j = 0; j < last_b; ++j)
    243                 if (name == ar_of_box[j].name)
    244                     ar_of_box[j].set_border(border);
    245         }
    246 
    247 
    248         if (s.find(".set_spacing") != s.npos){
    249             string name = "";
    250             int k = 0;
    251             int space = 0;
    252 
    253             while (s[k] != '.'){
    254                 name += s[k];
    255                 ++k;
    256             }
    257 
    258             while (s[k] != '(')
    259                 ++k;
    260             ++k;
    261 
    262             while (s[k] >= '0' && s[k] <= '9'){
    263                 space = space * 10 + s[k] - '0';
    264                 ++k;
    265             }
    266 
    267             for(int j = 0; j < last_b; ++j)
    268                 if (name == ar_of_box[j].name)
    269                     ar_of_box[j].set_space(space);
    270         }
    271 
    272     }
    273 
    274     for(int i = 0; i < last_b; ++i){
    275         res_ar[i].name = ar_of_box[i].name;
    276         res_ar[i].x = ar_of_box[i].x;
    277         res_ar[i].y = ar_of_box[i].y;
    278     }
    279 
    280     for(int i = 0; i < last_w; ++i){
    281         res_ar[i + last_b].name = ar_of_widget[i].name;
    282         res_ar[i + last_b].x = ar_of_widget[i].x;
    283         res_ar[i + last_b].y = ar_of_widget[i].y;
    284     }
    285 
    286     sort(&res_ar[0], &res_ar[last_b + last_w], comp);
    287 
    288     for(int i = 0; i < last_b + last_w; ++i)
    289         printf("%s %I64d %I64d
    ", res_ar[i].name.c_str(), res_ar[i].x, res_ar[i].y);
    290 }
    View Code

    E

    dfs+十字链表

    参考博客:https://blog.csdn.net/jnxxhzz/article/details/83067769

     1 #include<iostream>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define maxn 100005
     7 typedef long long ll;
     8 typedef unsigned long long ull;
     9 const ull MOD=257;
    10 /*#ifndef ONLINE_JUDGE
    11         freopen("1.txt","r",stdin);
    12 #endif */
    13 
    14 int n,m;
    15 string s[5005];
    16 int L[5005],R[5005],U[5005],D[5005];
    17 
    18 void init(){///十字链表初始化
    19     int b,pos;
    20     for(int i=0;i<n;i++){
    21         b=-1;
    22         for(int j=0;j<m;j++){
    23             if(s[i][j]!='.'){
    24                 pos=i*m+j;
    25                 L[pos]=b;
    26                 if(b!=-1)
    27                     R[b]=pos;
    28                 b=pos;
    29             }
    30         }
    31         R[b]=-1;
    32     }
    33 
    34     for(int i=0;i<m;i++){
    35         b=-1;
    36         for(int j=0;j<n;j++){
    37             if(s[j][i]!='.'){
    38                 pos=j*m+i;
    39                 U[pos]=b;
    40                 if(b!=-1){
    41                     D[b]=pos;
    42                 }
    43                 b=pos;
    44             }
    45         }
    46         D[b]=-1;
    47     }
    48 }
    49 
    50 int dfs(int now){
    51     int x=now/m,y=now%m;
    52     if(L[now]!=-1) R[L[now]]=R[now];
    53     if(R[now]!=-1) L[R[now]]=L[now];
    54     if(U[now]!=-1) D[U[now]]=D[now];
    55     if(D[now]!=-1) U[D[now]]=U[now];
    56 
    57     int go;
    58     if(s[x][y]=='U') go=U[now];
    59     else if(s[x][y]=='D') go=D[now];
    60     else if(s[x][y]=='L') go=L[now];
    61     else if(s[x][y]=='R') go=R[now];
    62     if(go==-1) return 1;
    63     return dfs(go)+1;
    64 }
    65 
    66 int main(){
    67     #ifndef ONLINE_JUDGE
    68      //   freopen("1.txt","r",stdin);
    69     #endif
    70     std::ios::sync_with_stdio(false);
    71     cin>>n>>m;
    72     for(int i=0;i<n;i++){
    73         cin>>s[i];
    74     }
    75     int ans=0,num=0,tmp;
    76     for(int i=0;i<n;i++){
    77         for(int j=0;j<m;j++){
    78             if(s[i][j]!='.'){
    79                 init();
    80                 tmp=dfs(i*m+j);
    81                 if(tmp==ans) num++;
    82                 else if(tmp>ans){
    83                     ans=tmp;
    84                     num=1;
    85                 }
    86             }
    87         }
    88     }
    89     cout<<ans<<" "<<num<<endl;
    90 }
    View Code
  • 相关阅读:
    Python深入:编码问题总结
    Search for a Range
    Search in Rotated Sorted Array
    WebStrom 多项目展示及vuejs插件安装
    高强度减脂Tabata练习
    webStrom 美化
    myeclipse 与 webstrom 免解析node_modules 的方法
    node-webkit 入门
    vue框架搭建
    Electron_01
  • 原文地址:https://www.cnblogs.com/Fighting-sh/p/10502385.html
Copyright © 2011-2022 走看看