【入门4】数组 (今天刷洛谷了嘛)

几道纯模拟题没有写,暂且先放一下

P1428

小鱼比可爱 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e6;
int s[109];
int ans[109]; 
int main()
{
	ios;
	int n;
	cin>>n;
	for(int i = 1;i<=n;i++)
	cin>>s[i];
	
	for(int i = 1;i<=n;i++)
	{
		int cnt = 0;
		for(int j = i-1;j>=1;j--)
		{
			if(s[i]>s[j])
			cnt++;
		}
		ans[i] = cnt;
	}
	for(int i = 1;i<=n;i++)
	cout<

P1427

小鱼的数字游戏 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e6;
int s[109];
int main()
{
	ios;
	int cnt = 0;
	while(1)
	{
		int t;
		cin>>t;
		if(!t)
		break;
		s[++cnt] = t;
	}
	for(int i = cnt;i>=1;i--)
	cout<

P5727

【深基5.例3】冰雹猜想 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e6;
int s[109];
int main()
{
	ios;
	int n;
	cin>>n;
	int cnt = 0;
	int q = n;
	while(n!=1)
	{
		if(n&1)
		n = n*3+1;
		else
		n = n/2;
		s[++cnt] = n;
	}
	for(int i = cnt;i>=1;i--)
	cout<

P1047

[NOIP2005 普及组] 校门外的树 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e4+9;
int s[N];
int main()
{
	ios;
	int n,m;
	cin>>n>>m;
	while(m--)
	{
		int l,r;
		cin>>l>>r;
		s[l] --;
		s[r+1] ++;
	 } 
	 int ans = 0;
	 int q = 0;
	 for(int i = 0;i<=n;i++)
	 {
	 	q += s[i];
	 	if(!q)
	 	ans++;
	 }
	 cout<

P5728

【深基5.例5】旗鼓相当的对手 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e4+9;
struct nn
{
	int a,b,c,sum;
	void add()
	{
		sum = a+b+c;
	}
}s[1009];
int main()
{
	int n;
	cin>>n;
	for(int i = 1;i<=n;i++)
	{
		cin>>s[i].a>>s[i].b>>s[i].c;
		s[i].add();
	}
	int ans = 0;
	for(int i = 1;i<=n;i++){
		for(int j = i+1;j<=n;j++)
		{
			if(abs(s[i].a-s[j].a)<=5&&abs(s[i].b-s[j].b
			)<=5&&abs(s[i].c-s[j].c)<=5&&abs(s[i].sum-
			s[j].sum)<=10)
			ans++;
		}
	}	
	cout<

P5729

【深基5.例7】工艺品制作 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e4+9;
bool s[25][25][25];
int main()
{
	ios;
	int a,b,c;
	cin>>a>>b>>c;
	int t;
	cin>>t;
	while(t--)
	{
		int x,y,z;
		int x2,y2,z2;
		cin>>x>>y>>z>>x2>>y2>>z2;
		for(int i = x;i<=x2;i++)
		for(int j = y;j<=y2;j++)
		for(int k = z;k<=z2;k++)
		s[i][j][k] = 1;
	}
	int ans = 0;
	for(int i = 1;i<=a;i++)
	for(int j = 1;j<=b;j++)
	for(int k = 1;k<=c;k++)
	if(!s[i][j][k])
	ans++;
	cout<

P2550

[AHOI2001]彩票摇奖 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e4+9;
int ans[10];
int main()
{
	ios;
	int n;
	cin>>n;
	int s[10];
	cin>>s[1]>>s[2]>>s[3]>>s[4]>>s[5]>>s[6]>>s[7];
	while(n--)
	{
		int cnt = 0;
		int q[10];
		cin>>q[1]>>q[2]>>q[3]>>q[4]>>q[5]>>q[6]>>q[7];
		for(int i = 1;i<=7;i++)
		{
			for(int j = 1;j<=7;j++)
			{
				if(s[i]==q[j])
				cnt++;
			}
		}
		ans[cnt]++;
	}
	for(int i = 7;i>=1;i--)
	cout<

P1554

梦中的统计 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e6;
int s[10];
int main()
{
	ios;
	int l,r;
	cin>>l>>r;
	for(int i = l;i<=r;i++)
	{
		int t = i;
		while(t)
		{
			s[t%10]++;
			t/=10;
		}
	}
	for(int i = 0;i<=9;i++)
	cout<

P2141

[NOIP2014 普及组] 珠心算测验 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 2e4+9;
bool s[N];
int p[109];
int t[N];
int main()
{
	ios;
	int n;
	cin>>n;
	for(int i = 0;i>p[i],s[p[i]] = 1;
	for(int i = 0;i

P1614

爱与愁的心痛 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e4;
int s[N];
int main()
{
	ios;
	int n,m;
	cin>>n>>m;
	for(int i = 1;i<=n;i++)
	cin>>s[i];
	int t = 0;
	int mn = 0;
	for(int i = 1;i<=m;i++)
	mn+=s[i];
	t = mn;
	for(int i = m+1;i<=n;i++)
	{
		t = t-s[i-m]+s[i];
		mn = min(mn,t);
	}
	cout<

P2911

[USACO08OCT]Bovine Bones G 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 100;
int s[N];
int main()
{
	ios;
	int a,b,c;
	cin>>a>>b>>c;
	for(int i = 1;i<=a;i++)
	for(int j = 1;j<=b;j++)
	for(int k = 1;k<=c;k++)
	s[i+j+k]++;
	int mx = 0;
	int ans = 0;
	for(int i = 1;i<=N;i++)
	{
		if(mx

P1161

开灯 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e7+5;
bool s[N];
int main()
{
	ios;
	int n;
	cin>>n;
	while(n--)
	{
		int t;double a;
		cin>>a>>t;
		for(int i = 1;i<=t;i++)
		{
			s[int(i*a)] = !s[int(i*a)];
		}
	}
	for(int i = 1;;i++)
	{
		if(s[i])
		{
			cout<

P5732

【深基5.习7】杨辉三角 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 100;
int s[25][25];
int main()
{
	ios;
	int n;
	cin>>n;
	for(int i = 1;i<=n;i++)
	{
		s[i][1] = 1,s[i][i] = 1;
	}
	for(int i = 3;i<=n;i++)
	for(int j = 2;j<=i-1;j++)
	s[i][j] = s[i-1][j]+s[i-1][j-1];
	for(int i = 1;i<=n;i++)
	{
		for(int j = 1;j<=i;j++)
		{
			cout<

P1789

【Mc生存】插火把 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 105;
bool s[N][N];
int n;
void hb(int x,int y)
{
	s[x][y] = 1;
	if(y-1>0)	s[x][y-1] = 1;
	if(y-2>0)	s[x][y-2] = 1;
	if(y+1<=n)	s[x][y+1] = 1;
	if(y+2<=n)	s[x][y+2] = 1;
	if(x-1>0)	s[x-1][y] = 1;
	if(x-2>0)	s[x-2][y] = 1;
	if(x+1<=n)	s[x+1][y] = 1;
	if(x+2<=n)	s[x+2][y] = 1;
	if(x-1>0&&y-1>0)	s[x-1][y-1] = 1;
	if(x+1<=n&&y+1<=n)	s[x+1][y+1] = 1;
	if(x-1>0&&y+1<=n)	s[x-1][y+1] = 1;
	if(x+1<=n&&y-1>0)	s[x+1][y-1] = 1;
}
void ys(int x,int y)
{
	for(int i = x-2;i<=x+2;i++)
	for(int j = y-2;j<=y+2;j++)
	{
		if(i>=1&&i<=n&&j>=1&&j<=n)
		s[i][j] = 1;
	}
}
int main()
{
	int m,k;
	cin>>n>>m>>k;
	for(int i = 1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		hb(x,y);
	}
	for(int i = 1;i<=k;i++)
	{
		int x,y;
		cin>>x>>y;
		ys(x,y);
	}
	int ans = 0;
	for(int i = 1;i<=n;i++)
	for(int j = 1;j<=n;j++)
	{
		if(!s[i][j])	ans++;
	}
	cout<

P1319

压缩技术 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e5;
bool s[N];
int main()
{
	int n;
	cin>>n;
	bool flag = 0;
	int cnt = 1; 
	int t;
	while(cin>>t)
	{
		if(!flag)
		for(int j = 1;j<=t;j++)
		s[cnt++] = 0;
		else
		for(int j = 1;j<=t;j++)
		s[cnt++] = 1;
		flag = !flag;
	}
	for(int i = 1;i<=cnt-1;i++)
	{
		cout<

P1320

压缩技术(续集版) 

#include
#include
#include
#include
#include
#include 
#include
#include 
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e5;
char s[N];
int an[N];
int cnt = 0;
int main()
{
	int ans = 0;
	bool flag = 1;
	int n;
	bool q = 0;
	while(cin>>s)
	{
		if(flag)
		{
			n = strlen(s);
			flag = 0;
		}
		for(int i = 0;i

你可能感兴趣的:(60天洛谷挑战flag,蓝桥杯,c++,职场和发展)