diverta 2019 Programming Contest 2

  A: attendance.

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,m;
signed main()
{
	n=read(),m=read();
	if (m==1) cout<<0;else cout<<n-m;
	return 0;
	//NOTICE LONG LONG!!!!!
}

  B: If all differences are (p, q) of the connecting point, a number of chains will be apparent, the number of chains is the answer. So long as the number of occurrences of each statistical difference can be.

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N 55
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
typedef pair<int,int> pii;
int n,ans;
struct data{int x,y;
}a[N];
map<pii,int> f;
signed main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i].x=read(),a[i].y=read();
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
		if (i!=j)
		{
			ans=max(ans,++f[make_pair(a[i].x-a[j].x,a[i].y-a[j].y)]);
		}
	cout<<n-ans;
	return 0;
	//NOTICE LONG LONG!!!!!
}

  C: Clearly should try to increase the number of positive burdens. But it is easy to find at least a number to be lost, at least to be coupled with a number, so both positive or both negative a little tinkering. You may assume is sorted before the number you want to lose p, plus a few others. Then let A . 1 sequentially subtracting A P +. 1 ~ A n--. 1 , and then make the A n- sequentially subtracting the A . 1 ~ A P can.

 

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N 100010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,a[N];
signed main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1);
	int p=0;
	for (int i=1;i<=n;i++) if (a[i]<0) p=i;
	p=max(p,1);p=min(p,n-1);
	//让前p个被减掉
	int s=0;
	for (int i=1;i<=p;i++)  s-=a[i];
	for (int i=p+1;i<=n;i++) s+=a[i];
	cout<<s<<endl;
	for (int i=p+1;i<n;i++)
	{
		printf("%d %d\n",a[p],a[i]);
		a[p]-=a[i];
	}
	printf("%d %d\n",a[n],a[p]);a[n]-=a[p];
	for (int i=1;i<p;i++)
	{
		printf("%d %d\n",a[n],a[i]);
		a[n]-=a[i];
	}
	return 0;
	//NOTICE LONG LONG!!!!!
}

 

  D: A to B apparent to A and the process B are independent, each can be optimized. Obviously do a full backpack. Note that the second complete backpack range is 5000 * 5000, and the answer will burst int.

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N (5010*5010)
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,a[2][3];
ll f[N];
ll solve(int x,int y,int n)
{
	for (int i=0;i<=n;i++) f[i]=i;
	for (int i=0;i<3;i++)
		for (int j=a[x][i];j<=n;j++)
		F [J] = max (F [J], F [JA [X] [I]] A + [Y] [I]); 
	return F [n]; 
} // sell dollars from an n x y sell last maximum number can be left 
Signed main () 
{ 
	n-= Read (); 
	for (int I = 0; I <2; I ++) 
		for (int J = 0; J <. 3; J ++) 
		A [I] [J ] = Read (); 
	COUT << Solve (1,0, Solve (0,1, n-)); 
	return 0; 
	// a LONG !!!!! NOTICE a LONG 
}
 

  E: set F [i] [j] is the maximum number of i and j has a number scheme, and embarrassing to use the minimum number required for the transfer, and can not be recorded. But he noted that the minimum value from a pick and in the process became one of a number of maximum is one to one, so when the new maximum will contribute directly to take into account. Then the above dp readily f [i] [j] = f [i] [j-1] * j, so long as the recording f [i] [1] and transferred.

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000010
#define N 1000010
#define P 1000000007
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,h,d,f[N],sum[N],s,t;
int ksm(int a,int k)
{
	int s=1;
	for (;k;k>>=1,a=1ll*a*a%P) if (k&1) s=1ll*s*a%P;
	return s;
}
int inv(int a){return ksm(a,P-2);}
signed main()
{
	n=read(),h=read(),d=read();
	s=t=1;
	for (int i=2;i<=n;i++)
	{
		t=1ll*t*i%P;
		s=(s+t)%P;
	}
	f[0]=inv(s);sum[0]=f[0];
	for (int i=1;i<=h;i++)
	{
		int u=(sum[i-1]-(i>d?sum[i-d-1]:0)+P)%P;
		f[i]=1ll*u*s%P;
		sum[i]=(sum[i-1]+f[i])%P;
	}
	for (int i=n;i>=1;i--) f[h]=1ll*f[h]*i%P;
	cout<<f[h];
	return 0;
	//NOTICE LONG LONG!!!!!
}

  result:rank 98 rating +38

 

Guess you like

Origin www.cnblogs.com/Gloid/p/11031179.html