http://192.168.14.232/contest/58

A:

这也能100
显然,完全图的三角形最多
易得n节点完全图中三角形数量为
Cn3
talk is cheap,show you the code

#include <bits/stdc++.h>
using namespace std;
inline int read_z(){int x=0;char ch=getchar();while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}return x;}
inline void write_z(int x){if(x>9){write_z(x/10);}putchar(x%10+'0');}
int tr[355],ans;
vector<int>TDL;//to do list
int main(){
	int n=read_z();
	tr[3]=1;
	for(int i=4;i<=350;i++)tr[i]=(long long)tr[i-1]*i/(i-3);
	for(int i=350;i>2;i--){
		while(tr[i]<=n){n-=tr[i],TDL.push_back(i),ans+=i;}
	}
	write_z(ans),putchar('\n');
	while(!TDL.empty()){
		for(int i=1;i<TDL[TDL.size()-1];i++)putchar('1'),putchar(' ');
		for(int i=TDL[TDL.size()-1];i<ans;i++)putchar('0'),putchar(' ');
		ans--;
		TDL[TDL.size()-1]--;
		if(TDL[TDL.size()-1]==0)TDL.pop_back();
		putchar('\n');
	}
}

B:

没写过交互题……
思路是这样的:
假设你的两端匹配上了

[........]

那么递归往里处理即可
I can't write code,so watch Liujiaxin's

#include <bits/stdc++.h> 
#include "memory.h"
using namespace std;
int Hash(int pos,int prepos,int sum,int knd){
	return (pos<<15)+(prepos<<8)+(sum<<1)+knd;
}
int Memory(int N, int M) {
	int pos=M>>15,prepos=(M>>8)&127,sum=(M>>1)&127,knd=M&1;
	if(sum>100||(prepos>pos&&prepos!=N+1)) return M;
	if(pos==0) return Hash(1,1,0,0);
	if(prepos==N+1){
		if(pos==N+1){
			if(!knd) return Hash(1,prepos,sum,1);
			if(sum) return -2;
			return -1;
		}
		if(pos>N||pos<1) return M;
		char ch=Get(pos);
		if(ch=='['||ch=='<') sum++;
		else sum--;
		if(sum<0) return -2;
		return Hash(pos+1,prepos,sum,knd);
	}
	if(pos==N+1) return -2;
	if(pos==prepos){
		if(pos>N||pos<1) return M;
		char ch=Get(pos);
		if(ch=='<') return Hash(pos+1,prepos,1,0);else
		if(ch=='[') return Hash(pos+1,prepos,1,1);else 
					return Hash(pos+1,prepos+1,0,0);
	}
	if(pos<1||pos>N) return M;
	char ch=Get(pos);
	if(ch=='<'||ch=='[') sum++;
	if(ch=='>'||ch==']') sum--;
	if(sum<0) return M;
	if(!sum){
		if(knd){
			if(ch==']') return Hash(prepos+1,prepos+1,0,0);
			else return -2;
		}else{
			if(ch=='>') return Hash(prepos+1,prepos+1,0,0);
			else return -2;
		}
	}
	return Hash(pos+1,prepos,sum,knd);
	return M;
}

C:

原来是压维dp
Liujiaxin's sol:
忘了
I can't write code,so watch Liujiaxin's

#include <bits/stdc++.h>
using namespace std;
const int maxn=1000005;
const int INF=0x3f3f3f3f;
int read(){
	int ret=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
	while( isdigit(ch)){ret=(ret<<3)+(ret<<1)+(ch&15);ch=getchar();}
	return ret*f;
}
int n;
struct line{
	int l,r;
	line operator&(const line &B){
		if(r==-1) return B;
		if(B.r==-1) return (line){l,r};
		return (line){min(l,B.l),max(r,B.r)};
	}
	line operator+(int now){
		if(r==-1) return (line){l,r};
		return (line){l+now,r+now};
	}
	bool conclude(int val){
		return l<=val&&val<=r;
	}
}f[maxn][2];
int a[maxn],b[maxn];
void DFS(int now,int num,int val){
	if(now==1) return ;
	if(f[now-1][0].conclude(num)&&val>=a[now-1]){
		DFS(now-1,num-1,a[now-1]);
		putchar('A');
	}else{
		DFS(now-1,num,b[now-1]);
		putchar('B');
	}
}
int main(){
	n=read()*2;
	for(int i=1;i<=n;++i) a[i]=read();
	for(int i=1;i<=n;++i) b[i]=read();
	for(int i=1;i<=n;++i){
		if(a[i]>=a[i-1]&&a[i]>=b[i-1]) f[i][0]=(f[i-1][0]+1)&(f[i-1][1]+1);
		else if(a[i]>=a[i-1]) f[i][0]=f[i-1][0]+1;
		else if(a[i]>=b[i-1]) f[i][0]=f[i-1][1]+1;
		else f[i][0]=(line){0,-1};
		if(b[i]>=a[i-1]&&b[i]>=b[i-1]) f[i][1]=f[i-1][0]&f[i-1][1];
		else if(b[i]>=a[i-1]) f[i][1]=f[i-1][0];
		else if(b[i]>=b[i-1]) f[i][1]=f[i-1][1];
		else f[i][1]=(line){0,-1};
	}
	if(!f[n][0].conclude(n/2)&&!f[n][1].conclude(n/2)){
		printf("-1");
		return 0;
	}
	DFS(n+1,n/2,INF);
	return 0;
}

D:

forget
I can't write code,so watch Liujiaxin's

#include <bits/stdc++.h>
using namespace std;
const int maxn=100005;
int read(){
	int ret=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
	while( isdigit(ch)){ret=(ret<<3)+(ret<<1)+(ch&15);ch=getchar();}
	return ret*f;
}
int n;
long long ans;
int sum[maxn],tmp[maxn];
void calc(int k){
	for(int i=0;i<=n;++i) tmp[i]=sum[i]-i*k;
	sort(tmp,tmp+n+1);
	int l=0;
	while(l<=n){
		int num=1;
		while(l< n&&tmp[l]==tmp[l+1]) l++,num++;
		ans+=1ll*num*(num-1)/2;
		l++;
	}
}
int main(){
	n=read();
	int mx=0,mn=101;
	for(int i=1;i<=n;++i){
		int now=read();
		sum[i]=sum[i-1]+now;
		mx=max(mx,now);
		mn=min(mn,now);
	}
	for(int i=max(mn,1);i<=mx;++i) calc(i);
	printf("%lld",ans);
	return 0;
}
posted @ 2024-10-20 18:46  yzc_is_SadBee  阅读(13)  评论(0)    收藏  举报