NYIST-20级寒假第二次周赛-个人补题+ans。

1202年 1月16日工作室第一次周赛:三小时七题。
AC 2 / 7题 : E,F;
知识点:。
比赛链接 < < 点我!!


E.计蒜客 T1555
知识点:二分答案(水)

AC代码:

#include<iostream>
#include<algorithm>

using namespace std;

const int N = 1e5 + 10;
int a[N];
int b;
bool cmp(int a,int b)
{
	return a < b;
}
	
bool check(int mid)
{
	if(a[mid] <= b) 
		return true;
	
	return false;
}
int main()
{
	int	n,m;
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	sort(a+1,a+n+1,cmp);
	while(m--)
	{	
		cin >> b;
		if(b < a[1])
		{
			cout << "-1"<<endl;
			continue;
		} 
		int l,r;
		l = 0, r = n;
		int mid = 0,ans;
		while(l < r)
		{
			mid = (r+l+1) / 2;
			if(check(mid)) 
			{
				ans = a[mid];
				l = mid;
			}
			else r = mid - 1;	
		}
		cout << ans << endl;
	} 
	return 0;
} 

F.Gym 101086G
知识点: 模拟;

AC代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

char mp[500][500];
long long res = -1;
int x[8] = {-1,-1,-1,0,0,1,1,1};
int y[8] = {-1,0,1,-1,1,-1,0,1};
int main()
{
	int T;
	cin >> T;
	while(T--)
	{
		long long n,ans;
		cin >> n;
		for(int i = 1; i <= 3; i++) scanf("%s",mp[i]+1);
		for(int i = 2;i<= n*3;i+=3)
		{	
			ans = 0;
			for(int j = 0; j <= 7; j++)
			{
				int nx = 2 + x[j];
				int ny = i + y[j];
				
				if(mp[nx][ny] == '*')
				{
					ans++;	
				}
			}
			res = max(res,ans);			
		}
		cout << res * 4 << endl;
		res = 0;	
	}	
} 

反思:emm, 没好好学,相当于什么也没做出来!

补题:

A.Catch That Cow

知识点: bfs;

AC代码:

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
const int ma = 2e5 + 10; // *** 注意 数组的size,这点很重要!!
int N,K;
bool sg[ma];
struct pt
{
	int p,step;
}now,tp;
int bfs()
{
	memset(sg,false,sizeof(sg));
	queue<pt> q;
	pt r;
	r.p = N;
	r.step = 0;
	sg[N] = true;
	q.push(r);
	
	while(!q.empty())
	{
		now = q.front();
		q.pop();
		
		if(now.p == K) return now.step;
		int np;
		for(int i = 1; i <= 3; i++)
		{
			if(i == 1) np = now.p - 1;
			else if( i == 2) np = now.p + 1;
			else 				np = now.p * 2;
			
			if(np < 0 || np > 100000) continue;
			if(sg[np]) continue;
			sg[np] = true;
			tp.p = np;
			tp.step = now.step + 1;
			q.push(tp);
		}
	}
}
int main()
{
	while(cin >> N >> K)
	{
		if(N >= K)
			cout << N - K << endl;
		else
			cout << bfs() << endl;	
	}
	return 0;
} 

B.CodeForces - 1430C

知识点: 逻辑题;

AC代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<stack>
using namespace std;
const int ma = 3e5 + 20;
int a[ma];
int n;

void fiction()
{
	stack<int> s;
	for(int i = 1; i <= n; i++)
	{
		s.push(i);
	}
	cout << '2' << endl;
	while(s.size() != 1)
	{
		int a = s.top();
		s.pop();
		int b = s.top();
		s.pop();
		cout << a << ' ' << b <<endl;
		s.push((a+b+1)/2);
	}
}
int main()
{
	int T;
	cin >> T;
	while(T--)
	{
		cin >> n;
		fiction();
	}
	return 0;
}

反思: 学习一下同学用Stack来解;

C.CodeForces - 1433C
知识点: 逻辑题;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int ma = 3e5 + 10;
int a[ma];
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int sum = 0 ,f ,maxx = -1;
		memset(a,0,sizeof(a));
		int n;
		cin >> n;
		for(int i = 1; i <= n; i++)
			cin >> a[i];
		for(int i = 1; i<= n; i++)
		{
			if(a[i] == a[1]) sum++;
			if(a[i] > maxx)
			{
				if(i == 1)
				{
					if(a[i] > a[i+1])
					{
						f = i; 	
						maxx = a[i];
					}	
				}
				else if(i == n)
				{
					if(a[i] > a[i-1])
					{
						f = i;
						maxx = a[i];
					}
				}
				else
				{
					if(a[i] > a[i-1] || a[i] > a[i+1])
					{
						f = i;
						maxx = a[i]; 
					}
				}
						
			}
			
		}
		if(n == sum) cout << "-1" << endl;
		else cout << f << endl;	
	}
	return 0;
}

反思: 这道题离谱!!! 因为可以输出any的答案 所以你只需要遍历一遍找到最大的🐟的位置即可!

D.HDU - 1372

知识点: BFS模板题;

题意: knight的走法同中国象棋中的 马的走法;(题目竟然不给个图!!英语也看不明白QAQ;

在这里插入图片描述
AC代码:

#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
char mp[10][10];
bool sg[10][10];
int x[8] = {1,2,2,1,-1,-2,-2,-1};
int y[8] = {2,1,-1,-2,-2,-1,1,2};
string a,b;
struct pt
{
	int x;
	int y;
	int step;
}now,tp;

void bfs()
{
	memset(sg,false,sizeof(sg));
	queue<pt> q;
	pt r;
	r.x = a[0] - 96;
	r.y = a[1] - 48;
	r.step = 0;
	sg[r.x][r.y] = true;
	q.push(r);
	
	while(!q.empty())
	{
		now = q.front();
		q.pop();
		
		if(now.x == (b[0] - 96) && now.y == (b[1]- 48)) 
		printf("To get from %c%c to %c%c takes %d knight moves.\n",a[0],a[1],b[0],b[1],now.step);
		
		for(int i= 0; i < 8; i++)
		{
			int nx = now.x + x[i];
			int ny = now.y + y[i];
			
			if(nx < 1 || nx > 8 || ny < 1 || ny > 8) continue;
			if(sg[nx][ny]) continue;
			sg[nx][ny] = true;
			
			tp.x = nx;
			tp.y = ny;
			tp.step = now.step + 1;
			q.push(tp);
		}
	}
}
int  main()
{
	
	while(cin >> a >> b) //string 不读空格,行; 
	{
		bfs();
	}
	return 0;
} 

反思: 如何读取 带空格的string?
答:
string s;
getline(cin,s);

G.CodeForces - 1263B

知识点: 逻辑题;

AC代码:

#include<iostream>
#include<cstring>
#include<string>
using namespace std;
string a[20];
bool sg[10000];
int main()
{
	int t,ans;
	cin >> t;
	while(t--)
	{ 
		ans = 0;
		memset(sg,false,sizeof(sg));
		int n;
		cin >> n;
		for(int i = 0; i< n ;i++)
		{
			cin >> a[i];
		}	
		for(int i = 0; i< n ;i++)
		{
			for(int j = i+1; j< n ;j++)
				if(a[i] == a[j]) 
				{
					ans++;
					for(int l = 0; l < n;l++)
					{
						sg[a[l][3] - '0'] = true;
					}
					for(int l = 0 ; l <= 9 ;l++)
					{
						if(!sg[l]) 
						a[j][3] = l + '0';
					}
				}
		}
		cout << ans << endl;
		for(int i = 0 ;i < n ;i++)
		cout << a[i] << endl;		
	}
	return 0;
}

反思:逻辑题都很精妙! 这道题因为最多只输入10个数所以让某一位为0 - 9 就可以了 ,很精妙! 芜湖

总结:这场总结: 两道BFS题都是非常基础 基础的,但是呢 读题后没有发现可以使用BFS来去解决这个问题,究其原因还是不完全明白BFS和DFS可以用于解决什么问题,其实就是做题少!!! 逻辑题占据了入门的很大一部分,以后要多多去思考,道阻且长,加油!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是51单片机控制的12864液晶显示系统编程实现所需的代码: ``` #include <reg51.h> #include <intrins.h> #define LCD_DB P0 sbit LCD_RS = P2^6; // RS信号 sbit LCD_RW = P2^5; // RW信号 sbit LCD_E = P2^7; // E信号 sbit LCD_CS1 = P2^0; // CS1信号 sbit LCD_CS2 = P2^1; // CS2信号 void delay(unsigned int i) // 延时函数 { while(i--); } void write_com(unsigned char com) // 写命令函数 { LCD_RS = 0; LCD_RW = 0; LCD_DB = com; LCD_E = 1; _nop_(); _nop_(); LCD_E = 0; } void write_data(unsigned char dat) // 写数据函数 { LCD_RS = 1; LCD_RW = 0; LCD_DB = dat; LCD_E = 1; _nop_(); _nop_(); LCD_E = 0; } void init_lcd() // 初始化函数 { write_com(0xc0); // 设置显示模式 write_com(0x3f); // 允许显示 write_com(0x40); // 设置起始地址 write_com(0xb8); // 设置页地址 write_com(0xc0); // 设置列地址 write_com(0x40); // 设置起始地址 write_com(0xb8); // 设置页地址 write_com(0xc0); // 设置列地址 } void display_string(unsigned char x, unsigned char y, unsigned char *s) // 显示字符串函数 { unsigned char i; if(y == 0) // 第一行居中显示“南阳理工学院” { write_com(0xb8 + x); write_com(0x40); } else if(y == 1) // 第二行居中显示“www.nyist.edu.cn” { write_com(0xb8 + x); write_com(0x48); } else if(y == 2) // 第三行居中显示“电子信息工程专业” { write_com(0xb8 + x); write_com(0x50); } else if(y == 3) // 第四行居中显示尚春芳 { write_com(0xb8 + x); write_com(0x58); } for(i = 0; s[i] != '\0'; i++) { write_data(s[i]); } } void main() { init_lcd(); // 初始化LCD display_string(18, 0, "南阳理工学院"); // 显示第一行 display_string(16, 1, "www.nyist.edu.cn"); // 显示第二行 display_string(16, 2, "电子信息工程专业"); // 显示第三行 display_string(22, 3, "尚春芳"); // 显示第四行 while(1); } ``` 以上代码实现了你提出的要求,第一行居中显示“南阳理工学院”,第二行居中显示“www.nyist.edu.cn”,第三行居中显示“电子信息工程专业”,第四行居中显示尚春芳。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值