Water solution to a problem man Q8 plan

T1 biological
meaning of the questions and the number is stored for each simulated to

#include<cstdio>
#define int long long
using namespace std;
int num[100010],a[100010];
signed main()
{
	//freopen("biology.in","r",stdin);
	//freopen("biology.out","w",stdout);
    int k;
    scanf("%d",&k);
    a[0]=1;
    for(int i=1;i<=k;i++)
    {
    	if(i%2==0) a[i]=i/2+1;
    	else a[i]=1;
    }
    num[0]=1;
    for(int i=1;i<=k;i++)
    {
    	num[i]=num[i-1]+a[i];
    }
    printf("%lld",num[k-1]);
    return 0;
}

  


T2 Chemical
difficult to find, the middle number of n can be emulated
number twenty-two difference of angle is ad, bc, da, cb
poor that is abs (ad) + abs (bc )
fixing a number of groups, can be done not to repeat the
last n can take on

#include<cstdio>
#include<cmath>
#define int long long
using namespace std;
signed main()
{
	//freopen("chemistry.in","r",stdin);
	//freopen("chemistry.out","w",stdout);
	int n;
	scanf("%lld",&n);
	int a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	int ans=(n-abs(a-d)-abs(b-c))*n;
	printf("%lld",ans);
	return 0;

}

  


T3 language
in 1 ~ n usury, the contribution will generate a 1 ~ i-1
DP [i] [j] denotes the number j i prior to contributions
as dp [i] [j] = sum_ {dp [i-1] [jk]} (k = 0 -> i-1)
easy to see and can be optimized using the prefix
last O (n * k)

#include<cstdio>
#include<cctype>
using namespace std;
const int mod=998244353;
int sum[5050][5050];
int dp[5050][5050];
int read()
{
  int f=1,x=0;
  char ch=' ';
  for(;!isdigit(ch);ch=getchar())if(ch=='-')f*=-1;
  for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
  return f*x;
}
int main()
{
	int n,m;
	n=read();
	m=read();
	dp[0][0]=1;
	for(int i=0;i<=m;i++)
	sum[0][i]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			if(i<=j) dp[i][j]=((dp[i][j]+sum[i-1][j])%mod-sum[i-1][j-i]+mod)%mod;
			else dp[i][j]=(dp[i][j]+sum[i-1][j])%mod;
			if(!j) sum[i][j]=dp[i][j];
			else sum[i][j]=(sum[i][j-1]+dp[i][j])%mod;
		}
	}
	printf("%lld\n",dp[n][m]);
	return 0;
}

  


T4 English
only 01 can be introduced, closest to the midpoint of the median can occur in two equal groups to count that the final solution is adjacent
drawing that can meet the dichotomy
directly to vertex 2 points

#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
int a[1000010];
int n;
int read()
{
  int f=1,x=0;
  char ch=' ';
  for(;!isdigit(ch);ch=getchar())if(ch=='-')f*=-1;
  for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
  return f*x;
}
int check(int x)
{
	for(int i=0;i<=n-2;i++)
	{
		if((a[n-i-1]>=x)==(a[n-i]>=x)) 
		return a[n-i-1]>=x;
		if((a[n+i+1]>=x)==(a[n+i]>=x)) 
		return a[n+i+1]>=x;
	}
	return a[1]>=x;
}
int main()
{
	n=read();
	int mmax=1;
	for(int i=1;i<=n*2-1;i++)
	{
		a[i]=read();
		mmax=max(mmax,a[i]);
	}
	int l=1,r=mmax;
	int ans=1;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(check(mid)) l=mid+1,ans=mid;
		else r=mid-1;
	}
	printf("%d",ans);
} 

  


T5 geographic
consider maintaining two Fenwick tree
subtracting the r l <= R in <= L to the

#include<cstdio>
#define lowbit(x) x&(-x)
#define int long long
using namespace std;
int n;
struct Node
{
  int a[200010];
  void add(int x)
  {
	while(x<=n)
	{
		a[x]++;
		x+=lowbit(x);
	}
  }  
  int count(int x)
  {
	int sum=0;
	while(x!=0)
	{
		sum+=a[x];
		x-=lowbit(x);
	}
	return sum;
  }
};
Node ans1,ans2;
signed main()
{	
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		int opt;
		scanf("%lld",&opt);
		if(opt==1)
		{
			int l,r;
			scanf("%lld%lld",&l,&r);
			ans1.add(l);	
			ans2.add(r);
		}
		else
		{
			int l,r;
			scanf("%lld%lld",&l,&r);
			int ans=ans1.count(r)-ans2.count(l-1);
			//printf("%d %d \n",ans1.count(r),ans2.count(l-1));
			printf("%lld\n",ans);		
		}
	}
}

  


T6 history
record the number of pi-1 in the number of occurrences of each front
and maintenance of the entire sequence of the maximum value
of each incoming only determines whether a number is greater than the maximum value to
be greater than that is selected, whereas selecting the original value, and place this number the sequence

#include<cstdio>
#include<cctype>
using namespace std;
int a[1000010],num[1000010]; 
int read()
{
  int f=1,x=0;
  char ch=' ';
  for(;!isdigit(ch);ch=getchar())if(ch=='-')f*=-1;
  for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
  return f*x;
}
int main()
{
	//freopen("history_2.in","r",stdin);
	//freopen("history.out","w",stdout);
	int n=read();
	for(int i=1;i<=n;i++)
	a[i]=read();
	int t=read();
	while(t--)
	{
		int p=read();
		int ans1=0,ans2=0;
		for(int i=1;i<p;i++) num[a[i]]++;
		int pos=n;
		for(int i=p;i<=n;i++)
		{
			int opt;
			if(a[i]>=pos) opt=a[i];
			else
			{
				num[a[i]]++;
				while(!num[pos]&&pos) pos--;
				num[pos]--;
				opt=pos;
			}
			if((i-p+1)%2) ans1+=opt;
			else ans2+=opt;
		}
		for(int i=1;i<p;i++)
		{
			int opt;
			while(!num[pos]&&pos) pos--;
			num[pos]--;
			opt=pos;
			if((i+(n-p+1))%2) ans1+=opt;
			else ans2+=opt;
		}
		printf("%d\n",ans1-ans2);		
	}
 	return 0;
}

  T7,8 because of too much food can not write QAQ

Guess you like

Origin www.cnblogs.com/ninelifecat/p/11488414.html