codeforces#363 Div2

Source: Internet
Author: User
Tags bitset cmath

Question A:

Test instructions: Given some number, given some of the operation to go left and go right, ask whether it can meet, if meet request meet time

Analysis: For the adjacent two number, if the large to the left, small to the right can meet, otherwise can not meet, in finding out all meet in the first encounter can

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <string>5#include <vector>6#include <algorithm>7#include <Set>8#include <map>9#include <bitset>Ten#include <cmath> One#include <queue> A#include <stack> - using namespacestd; - Const intmaxn=200050; the Const intinf=1<< -; - intA[MAXN]; - intN; - intMain () + { -      while(cin>>N) +     { A         strings; atCin>>s; -          for(intI=0; i<n;i++) -Cin>>A[i]; -         intflag=0; -         intK; -         intminx=INF; in          for(intI=0; i<n-1; i++) -         { to             intflag1=0; +             if(s[i]=='R'&&s[i+1]=='L'&&a[i]<a[i+1]) -             { theflag=1; flag1=1; *             } $             Else if(s[i]=='L'&&s[i+1]=='R'&&a[i]>a[i+1]){Panax Notoginsengflag=1; flag1=1; -             } the             if(FLAG1) { +                 intMaxt=max (a[i],a[i+1]); A                 intMint=min (a[i],a[i+1]); the                 intt= (Maxt-mint)/2; +                 if(t<Minx) -minx=T; $             } $         } -         if(flag) { -cout<<minx<<Endl; the}Else -         {Wuyicout<<"-1"<<Endl; the         } -     } Wu     return 0; -}
View Code

Question B:

Test Instructions: * Represents the Wall,. On behalf of the open space, a bomb can blow up a column of walls, asking if you can pass a bomb to make all of them flat.

Analysis: This is a hack point a lot of questions, I just because this question was hack, ranting once back to liberation. Direct simulation can be, but notice two cases, one is not a lattice is the case of the wall, there is a choice to place the bomb point is not the case of the wall

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <string>5#include <vector>6#include <algorithm>7#include <Set>8#include <map>9#include <bitset>Ten#include <cmath> One#include <queue> A#include <stack> - using namespacestd; - Const intmaxn=1100; the intn,m; - intVIS[MAXN],D[MAXN]; - intMain () - { +      while(cin>>n>>m) -     { +         CharS[MAXN][MAXN]; A          for(intI=0; i<n;i++) atCin>>S[i]; -         intflag1=0; -          for(intI=0; i<n;i++){ -              for(intj=0; j<m;j++){ -                 if(s[i][j]=='*'){ -flag1=1; Break; in                 } -             } to         } +         if(!Flag1) { -cout<<"YES"<<Endl; thecout<<"1"<<" "<<"1"<<Endl; *             Continue; $         }Panax Notoginsengmemset (Vis,0,sizeof(Vis)); -memset (D,0,sizeof(d)); the         intflag=0; +         intCnt=0; A          for(intI=0; i<n;i++) the         { +              for(intj=0; j<m;j++){ -                 if(s[i][j]=='*'){ $vis[i]++; $d[j]++; -cnt++; -                 } the             } -         }Wuyi         inth,k; the          for(intI=0; i<n;i++){ -              for(intj=0; j<m;j++){ Wu                 if(s[i][j]=='*'){ -                     if(vis[i]+d[j]==cnt+1){ AboutH=i; K=j; flag=1; Break; $                     } -}Else if(s[i][j]=='.'){ -                     if(vis[i]+d[j]==CNT) { -H=i;k=j; flag=1; Break; A                     } +                 } the             } -             if(flag) Break; $         } the         if(flag) { thecout<<"YES"<<Endl; thecout<1<<" "<<k+1<<Endl; the}Else{ -cout<<"NO"<<Endl; in         } the     } the     return 0; About}
View Code

codeforces#363 Div2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.