qbxt 第五套

三角形

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define LL long long
using namespace std;
LL read(){
	LL x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
	    ch=getchar();
	}
	while(ch<='9'&&ch>='0'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
const int N=300007;
LL n,num,f[N],ans=0;
struct node{
	LL a,b;
	#define a(x) c[x].a
	#define b(x) c[x].b
}c[N];
inline LL gcd(LL x,LL y){
	if(y==0) return x;
	else return gcd(y,x%y);
}
inline bool cmp(const node &x,const node &y){
	if(x.a!=y.a) return x.a<y.a;
	return x.b<y.b; 
}
inline LL C(LL x,LL y){
	if(x<y) return 0;
	LL sum1=1,sum2=1;
	for(register int i=x;i>=x-y+1;i--) sum1*=i;
	for(register int i=1;i<=y;i++) sum2*=i;
	return sum1/sum2;
}
int main(){
	freopen("trokuti.in","r",stdin);
	freopen("trokuti.out","w",stdout);
	n=read();
	LL x;
	for(register int i=1;i<=n;i++){
		a(i)=read();b(i)=read();x=read();
		if(a(i)&&b(i)){
		    LL xx=abs(a(i)),yy=abs(b(i));
			LL z=gcd(xx,yy);
			a(i)=a(i)/z;
			b(i)=b(i)/z;
		}
	} 
	sort(c+1,c+n+1,cmp);
	for(register int i=1;i<=n;i++){
		if(a(i)!=a(i-1)||b(i)!=b(i-1)){
			num++;f[num]=1;
		}
		else f[num]++;
	}
	ans=C(n,3);
	for(register int i=1;i<=num;i++)
	 ans=ans-C(f[i],2)*(n-f[i])-C(f[i],3);
	printf("%lld",ans);
	fclose(stdin);fclose(stdout); 
	return 0;
} 

最长上升子序列

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define LL long long
using namespace std;
LL read(){
	LL x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
	    ch=getchar();
	}
	while(ch<='9'&&ch>='0'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
const int N=100007;
int n,st[N],top;
int main(){
	freopen("manage.in","r",stdin);
	freopen("manage.out","w",stdout);
	n=read();
	int x;
	st[0]=-99999999;
	for(int i=1;i<=n;i++){
		x=read();
		if(x>st[top]){
			top++;
			st[top]=x;
		}
		else{
			int l=1,r=top,wz=0;
			while(l<=r){
				int mid=(l+r)/2;
				if(st[mid]>x){
					wz=mid;r=mid-1;
				}else l=mid+1;
			}
			st[wz]=x;
		}
	}
	printf("%d",top);
	fclose(stdin);fclose(stdout);
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值