Codeforces Round #587 (Div. 3)

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

A. Prefixes
代码:

#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,r;
ll ans=0;
ll a[maxn];  
int main()
{
 speed;
 cin>>n;
 string str;
 cin>>str;
 for(ll i=0;i<n;i++){
  if(i%2==0){
   s.push(str[i]);
  }
  else{
   if(s.top()==str[i]){
    ans++;
    if(s.top()=='a')
     str[i]='b';
    else
     str[i]='a';
   }
   s.pop();
  }
 }
 cout<<ans<<"\n";
 cout<<str<<"\n";
} 

B. Shooting
代码:

#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;
ll ans=0;
ll a[maxn];  
struct node{
 ll id,num;
}b[maxn];
bool cmp(node a,node b)
{
 return a.num>b.num;
}
int main()
{
 cin>>n;
 for(ll i=0;i<n;i++){
  cin>>a[i];
  b[i].num=a[i];
  b[i].id=i+1;
 }
 sort(b,b+n,cmp);
 for(ll i=0;i<n;i++){
  ans+=i*b[i].num+1;
 }
 cout<<ans<<"\n";
 for(ll i=0;i<n;i++){
  cout<<b[i].id<<" ";
 }
} 

C. White Sheet
代码:

#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;
ll ans=0;
ll a[maxn];  
int main()
{
 ll x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6;
 cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4>>x5>>y5>>x6>>y6;
 if(x3<=x1&&x4>=x2){
  if(y4>=y2&&y3<=y1){
   cout<<"NO\n";
   return 0;
  }
  else if(y4>=y2&&y3>y1&&y3<=y2){
   y2=y3;
  }
  else if(y3<=y1&&y4<y2&&y4>=y1){
   y1=y4;
  }
 }
 else if(y4>=y2&&y3<=y1){
  if(x3<=x1&&x4>=x2){
   cout<<"NO\n";
   return 0;
  }
  else if(x3<=x1&&x4<x2&&x4>=x1){
   x1=x4;
  }
  else if(x4>=x2&&x3>x1&&x3<=x2){
   x2=x3;
  }
 }
 if(x5<=x1&&y5<=y1&&x6>=x2&&y6>=y2){
  cout<<"NO\n";
 }
 else
  cout<<"YES\n";
} 

你妈的给人×了,早上起来改了小细节

D. Swords
代码:

#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;
ll ans=0;
ll a[maxn],b[maxn]; 
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
} 
int main()
{
 cin>>n;
 ll maxx=0;
 for(ll i=0;i<n;i++){
  cin>>a[i];
  maxx=max(maxx,a[i]);
 }
 ll sum=0,j=0;
 for(ll i=0;i<n;i++){
  sum+=maxx-a[i];
  if(maxx-a[i]!=0)
  b[j++]=maxx-a[i];
 }
 ll tmp=b[0];
 for(ll i=1;i<j;i++){
  tmp=__gcd(tmp,b[i]);
 }
 cout<<sum/tmp<<" "<<tmp<<"\n";
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值