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

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

A. Optimal Currency Exchange

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<stack> 
#include<cstring>
#include<map>
#include<queue> 
#include<cmath>
#include<set> 
#include<deque>
#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<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<stack> 
#include<cstring>
#include<map>
#include<queue> 
#include<cmath>
#include<set> 
#include<deque>
#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<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<stack> 
#include<cstring>
#include<map>
#include<queue> 
#include<cmath>
#include<set> 
#include<deque>
#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<<s.top();
   s.pop();
  }*/
  if(l==r)
   flag=1;
  if(s.size()<=3&&flag==1)
   cout<<"Yes\n";
  else
   cout<<"No\n";
 }
} 

D Treasure Island

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<stack> 
#include<cstring>
#include<map>
#include<queue> 
#include<cmath>
#include<set> 
#include<deque>
#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";
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值