Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises)

链接:http://codeforces.com/contest/1214

A. Optimal Currency Exchange

#include
#include
#include
#include
#include 
#include
#include
#include 
#include
#include 
#include
#define INF 0x3f3f3f3f
#define lowbit(a) ((a)&-(a))
#define speed std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
typedef long long ll;
queue<ll> q;
stack<ll> s;
deque<ll> deq;
priority_queue<ll> pq;  
const ll maxn = 200005;
ll n,m,l,r,k;
ll ans=0;
ll a[maxn]; 
int main()
{
 cin>>n>>m>>k;
 ll sum=0,minn=INF;
 while(sum*k*5<=n){ //枚举 
  minn=min(minn,(n-sum*5*k)%m);
  sum++;
 }
 cout<<minn<<endl;
} 

B. Badges

#include
#include
#include
#include
#include 
#include
#include
#include 
#include
#include 
#include
#define INF 0x3f3f3f3f
#define lowbit(a) ((a)&-(a))
#define speed std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
typedef long long ll;
queue<ll> q;
stack<ll> s;
deque<ll> deq;
priority_queue<ll> pq;  
const ll maxn = 200005;
ll n,m,l,r,k;
ll ans=0;
ll a[maxn]; 
int main()
{
 cin>>m>>k>>n;
 n+=1;
 ll minn=min(m,k);
 if(n-1-minn<=0){ //小的大于要求 
  cout<<n<<endl;
 }
 else{ //小的小于要求 
  if(n-1-max(m,k)<=0) //求不能成立的数量 
   cout<<minn+1<<endl;
  else
   cout<<minn+1-n+1+max(m,k)<<endl;
 }
 return 0;
} 

C. Bad Sequence

#include
#include
#include
#include
#include 
#include
#include
#include 
#include
#include 
#include
#define INF 0x3f3f3f3f
#define lowbit(a) ((a)&-(a))
#define speed std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
typedef long long ll;
queue<ll> q;
stack<char> s;
deque<ll> deq;
priority_queue<ll> pq;  
const ll maxn = 200005;
ll n,m,l=0,r=0;
ll ans=0;
ll a[maxn];
char str[maxn]; 
int main()
{
 cin>>n;
 scanf("%s",str);
 ll len=strlen(str);
 if(n%2)
  cout<<"No\n";
 else{
  ll flag=0;
  s.push('|');
  s.push(str[0]);
  if(str[0]=='(')
   l++;
  else
   r++;
  for(ll i=1;i<len;i++){
   if(str[i]=='(')
    l++;
   else
    r++;
   if(str[i]==')'&&s.top()=='('){ //不知道为什么,如果是空的stack就不可以,所以前面要预处理一下 
    s.pop();
   }
   else{
    s.push(str[i]);
   }
  }
  /*while(!s.empty()){
   cout<
  if(l==r)
   flag=1;
  if(s.size()<=3&&flag==1)
   cout<<"Yes\n";
  else
   cout<<"No\n";
 }
} 

D Treasure Island

#include
#include
#include
#include
#include 
#include
#include
#include 
#include
#include 
#include
#define INF 0x3f3f3f3f
#define lowbit(a) ((a)&-(a))
#define speed std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
typedef long long ll;
queue<ll> q;
stack<ll> s;
deque<ll> deq;
priority_queue<ll> pq;  
const ll maxn = 1000050;
ll n,m,l,r;
ll ans=0;
char a[maxn];
ll vis[maxn];
bool dfs(ll x,ll y)
{
 if(x<0||y>=m||y<0||x>=n||vis[x*m+y]||a[x*m+y]=='#') return false;
 if(y==m-1&&x==n-1) return true;
 if(x!=0||y!=0) vis[x*m+y]=1;
 return dfs(x+1,y)||dfs(x,y+1); //只需要标记一条线即可,所以是‘|| ’ 
}
int main()
{
 cin>>n>>m;
 for(ll i=0;i<n;i++)  //二维字符数组的一维输入 
  scanf("%s",a+i*m);
 if(!dfs(0,0)){
  cout<<"0\n"; 
  return 0;
 }
 if(!dfs(0,0)){
  cout<<"1\n";
  return 0;
 }
 cout<<"2\n";
} 

你可能感兴趣的:(cf)