码迷,mamicode.com
首页 > 其他好文 > 详细

Educational Codeforces Round 23 A-F 补题

时间:2017-06-16 13:28:58      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:%x   number   comm   syn   code   维护   amp   nbsp   main   

Treasure Hunt

注意负数和0的特殊处理。。 水题。。 然而又被Hack了 吗的智障

#include<bits/stdc++.h>
using namespace std;







int main()
{
 int sa,sb,da,db,x,y;
 scanf("%d%d%d%d%d%d",&sa,&sb,&da,&db,&x,&y);
 sa=da-sa;sb=db-sb;
 if(sa<0)sa*=-1;
 if(sb<0)sb*=-1;
 if(x<0)x*=-1;
 if(y<0)y*=-1;
 if((sa!=0&&x==0)||(sb!=0&&y==0)){printf("NO\n");return 0;}
 if((sa==0)&&(sb==0)){printf("YES\n");return 0;}
 if(((sa%x)!=0)||((sb%y)!=0)){printf("NO\n");return 0;}
 if((((max(sa/x,sb/y))-(min(sa/x,sb/y)))%2)!=0){printf("NO\n");return 0;}
 printf("YES\n");
 return 0;
}

Makes And The Product

排序后求一下组合数就好了。。

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int N=2e5;
LL num[N];
map<LL,LL>ma;




LL C(LL n,LL m)
{
 LL ans=1;
 for(int i=0;i<m;i++)
 	ans*=n-i;
 for(int i=m;i>=2;i--)
 	ans/=i;
 return ans;
}
int main()
{
 int n;
 scanf("%d",&n);
 for(int i=0;i<n;i++)scanf("%I64d",num+i);
 sort(num,num+n);
 LL ans=1;
 for(int i=0;i<3;i++)
 	ma[num[i]]++;
 LL l=ma[num[2]];
 for(int i=3;i<n&&num[i]==num[2];i++)
 	{
 	 l++;
	}
 ans=ans*C(l,ma[num[2]]);
 printf("%I64d\n",ans);
 return 0;
}

Really Big Numbers

肯定存在某个数k 大于k的数都是big number... 二分找最小的k就好了

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;


LL sum(LL x)
{
 LL dex=1;
 LL ans=0;
 while(x>0)
 	{
 	 ans+=((x%10)*(dex-1));
 	 x/=10;dex*=10;
	}
 return ans;
}



int main()
{
 LL n,s;
 scanf("%I64d%I64d",&n,&s);
 LL l=1,r=n;
 LL i;
 bool flag=false;
 LL ri;
 while(l<=r&&r<=n)
 	{
 	  i=(l+r)>>1;
 	 if(sum(i)>=s){flag=true;ri=i;r=i-1;}
 	 	else {l=i+1;}
	}
if(flag) {printf("%I64d\n",(n-ri+1));return 0;}
 	else printf("0\n");
 return 0;
}

Imbalanced Array

暴力枚举每个区间 复杂度O(n^2)起步 显然是不可以的。

那么只能考虑每个位置对答案做的贡献。即它是多少个区间的最值?

用栈维护,从前往后一个一个堆栈,并且保证栈中的所有元素构成不上升序列即可。

复杂度O(n)技巧性还是很强的。。

#include <bits/stdc++.h>
using namespace std;
long long n,pos[1000005],neg[1000005];
long long solve(long long a[]){
	stack<pair<int,long long>> s;
	a[n]=1e8;
	s.push({-1,1e9});
	long long sum=0;
	for(int i=0;i<=n;s.push({i,a[i]}),++i)
		while(a[i]>s.top().second){
			auto p=s.top();
			s.pop();
			auto p2=s.top();
			sum+=p.second*(i-p.first)*(p.first-p2.first);
		}
	return sum;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<n;neg[i]=(-1)*pos[i],++i)
		cin>>pos[i];
	cout<<solve(pos)+solve(neg);
}

Choosing The Commander

MEX Queries

 

Educational Codeforces Round 23 A-F 补题

标签:%x   number   comm   syn   code   维护   amp   nbsp   main   

原文地址:http://www.cnblogs.com/heisenberg-/p/7026881.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!