链接: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";
}