期末***温赛

天纵少年总该倚竹畅饮好云烟

风华羡尽俗人眼

兰亭曲水漫漫古今俯仰无愧欠

世事万变唯胸怀旷远

(全是水题预警,实在实在太***的题我就不往上贴了,太***了)
盲猜一手以后博客不会更这种sb题了
G
归并排序求逆序对(我本来写的树状数组但是莫名奇妙WA掉了,我就随便改了一个x写法QWQ)

/* Author: 张皓南 Result: AC Submission_id: 2644937 Created at: Sat May 23 2020 20:17:50 GMT+0800 (China Standard Time) Problem_id: 3419 Time: 10 Memory: 1676 */

#include <stdio.h>
int n;
int a[40005];
int tem[40005];
int ans=0;
inline void mergesort(int l,int m,int r)
{
   
	int i=l;
	int k=l;
	int j=m+1;
	while(i<=m&&j<=r)
	{
   
		if(a[i]>a[j])
		{
   
			tem[k++]=a[j++];
			ans+=m-i+1;
		}
		else 
		{
   
			tem[k++]=a[i++];
		}
	}
	while(i<=m) tem[k++]=a[i++];
	while(j<=r)  tem[k++]=a[j++];
	for(int i=l;i<=r;i++) a[i]=tem[i];
}
void me(int l,int r)
{
   
	if(l<r)
	{
   
		int mid=(l+r)>>1;
		me(l,mid);
		me(mid+1,r);
		mergesort(l,mid,r);
	}
	
}
int main()
{
   
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	me(1,n);
printf("%d",ans);
	return 0;
}

I
啊一开始写的快排+一些优化以为nlog能卡过去,可能数据放了卡快排的,没过去。yy一下,可以知道首项和尾项,所以可以搞出公差,然后判断两个数之间的差距是不是公差(莫得推导yy的)

/* Author: 张皓南 Result: AC Submission_id: 2644926 Created at: Sat May 23 2020 20:09:57 GMT+0800 (China Standard Time) Problem_id: 3421 Time: 28 Memory: 3636 */

#include <stdio.h>
#include <math.h>
#include <string.h>
int n,a[1000005];
int read(){
   
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
   if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){
   x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int main(){
   
    n=read();
	for(int i=1;i<=n;i++) a[i]=read();	
	if(n==1||n==2){
   
		printf("Yes");
	}
	else{
   
		int minn=2147483640;
		int maxx=-2147483640;
		for(int i=1;i<=n;i++){
   
			if(a[i]<minn) minn=a[i];
			if(a[i]>maxx) maxx=a[i];
		}
		int gc=(maxx-minn)/(n-1);
		if(gc==0){
   
			int flag=0;
			for(int i=1;i<=n;i++){
   
				if(a[i]!=minn){
   
					printf("NO");
					flag=1;
					break;
				}
			}
			if(!flag) printf("Yes");
		}
		else{
   
			int flag=0;
			int ci;
			for(int i=2;i<=n;i++){
   
				int gg=a[i]-a[i-1];
				ci=gg/gc;
				if(ci*gc!=gg){
   
					printf("NO");
					flag=1;
					break;
				}
			}
				if(!flag) printf("Yes");
		} 
	}
	return 0;
}

K
谔谔

/* Author: 张皓南 Result: AC Submission_id: 2645386 Created at: Sun May 24 2020 13:57:02 GMT+0800 (China Standard Time) Problem_id: 3422 Time: 9 Memory: 2584 */

#include <stdio.h>
#include <math.h>
#include <string.h>
char zhn[200005];
int dp[200005];
inline int read(){
   
	int x=0,f=1;
	char ch=getchar();
    while(ch<'0'||ch>'9'){
   if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){
   x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int main(){
   
	scanf("%s",zhn);
	int len=strlen(zhn);
	memset(dp,0,sizeof(dp));
	for(int i=0;i<len;i++){
   
	   if(zhn[i]=='1') dp[i]=dp[i-1]+1;
	   else dp[i]=0;	
	}
	int ans=0;
	for(int i=0;i<len;i++){
   
		if(dp[i]>ans) ans=dp[i];
	}
	printf("%d",ans);
	return 0;
}

L
板子

/* Author: 张皓南 Result: AC Submission_id: 2645395 Created at: Sun May 24 2020 14:09:24 GMT+0800 (China Standard Time) Problem_id: 3424 Time: 63 Memory: 1872 */

#include <stdio.h>
#include <math.h>
#include <string.h>
int top=0;
int tep=0;
char lgr;
int flag=0;
int dui[100005];
struct NODE{
   
	char a;
	int id;
}sta[100005];
int main(){
   
	while(scanf("%c",&lgr)!=EOF){
   
		if(lgr=='('||lgr=='{'){
   
			top++;
			tep++;
			sta[top].a=lgr;
			sta[top].id=tep;
		}
		else if(lgr=='}'||lgr==')'){
   
			tep++;
			if(lgr==')'){
   
				if(sta[top].a=='('){
   
				    dui[tep]=sta[top].id;
					dui[sta[top].id]=tep;
					top--;	
				}
				else flag=1;
			}
			else {
   
				if(sta[top].a=='{'){
   
				    dui[tep]=sta[top].id;
					dui[sta[top].id]=tep;
					top--;	
				}
				else flag=1;
			}
		}
	}
	
	if(flag||top)printf("NO");
	else if(!flag){
   
		for(int i=1;i<=tep;i++) printf("%d\n",dui[i]);
	}
	return 0;
}
全部评论

相关推荐

头像
05-14 12:29
安卓
点赞 评论 收藏
转发
1 收藏 评论
分享
牛客网
牛客企业服务