首页 > 其他分享 >8.20号考试总结

8.20号考试总结

时间:2024-08-20 22:04:47浏览次数:6  
标签:总结 int 31 long month mouth 8.20 考试 define

1.考点

时间

1.闰年判断

2.年,月,日判断是否合法

3.回文字符串判断

4.年,月,日,小时,秒的进位

2.考试成绩

题目: T1 T2 T3 T4 T5 T6 总分
分数: 100 100 36 10 0 0 246
难度: 入门 入门 普及- 普及/提高- 普及- 普及/提高-

3.错误点

T3.[蓝桥杯 2017 省 B] 日期问题:写了暴力代码,但是没法补零和if判断太多,导致最后自己也不知道哪里出现了BUG

T4.[蓝桥杯 2020 省 AB2] 回文日期:只对了一个测试点,纯属运气。因为解法有问题,而且只判断了前半部分,导致后半部分是否回文无法判断

T5.小挖的时间/T6.2038年问题:由于当时正在改T3和T4的代码部分,导致最后没有时间思考这两道题目,所以cout样例就直接交上去了

4.改题

T3.[蓝桥杯 2017 省 B] 日期问题

题目注意点:

1.不要暴力,用for循环一个一个循环出来年,月,日,时间十分充足

2.检测循环出来的时间能否对的上要写一个函数,否则十分混乱

3.要补零的地方要补零

4.判断时要把四位数字的年份变成两位数字,因为输入时就是两位

补题后代码

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int N1 = 1e3 + 2;
typedef long long ll;
typedef unsigned long long ull;
//#define int long long
//#define fo(i,n,m) for(int i=n;i<=m;i++)
int mouth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},a,b,c;
bool check(int x)//闰年判断板子
{
	if((x%400==0)||(x%4==0&&x%100!=0))
	{
		return 1;
	}
	return 0;
}
bool ct(int x,int y,int z) //用ct函数判断是否为输入的数字
{
	if(a==x&&b==y&&c==z)
	{
		return 1;
	}
	else if(c==x&&b==z&&a==y)
	{
		return 1;
	}
	else if(c==x&&b==y&&a==z)
	{
		return 1;
	}
	return 0;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	char chuhao;
	cin>>a>>chuhao>>b>>chuhao>>c;
	for(int i=1960;i<=2059;i++)
	{
		if(check(i))//判断闰年
		{
			mouth[2]=29;
		}
		else
		{
			mouth[2]=28;
		}
		for(int j=1;j<=12;j++)
		{
			for(int k=1;k<=mouth[j];k++)
			{
				int nian=i/10%10*10+i%10;//要算出来这里的年份,因为输入时的年份只有两位
				if(ct(nian,j,k))
				{
					cout<<i<<'-'<<setw(2)<<setfill('0')<<j<<'-'<<setw(2)<<setfill('0')<<k<<'\n'; //如果只有一位数要补零
				}
			}
		}
	}
	return 0;
}

T4.[蓝桥杯 2020 省 AB2] 回文日期

题目注意点

1.从一天一天来算,一秒一秒来算回超时

2.判断ABABBABA结构和回文结构要各写一个函数,而且只能存储第一个回文日期,所以还要打上标记

3.随时都要判断是否可以进位

补题后代码

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int N1 = 1e3 + 2;
typedef long long ll;
typedef unsigned long long ull;
//#define int long long
//#define fo(i,n,m) for(int i=n;i<=m;i++)
int mouth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool check(int x)//闰年判断板子
{
	if((x%400==0)||(x%4==0&&x%100!=0))
	{
		return 1;
	}
	return 0;
}
bool ct(string a)//判断是否回文
{
	string ans="";
	int len=a.length();
	for(int i=0;i<len;i++)
	{
		ans=a[i]+ans;
	}
	return ans==a;
}
bool huiwen(string a)//判断是否为ABABBABA结构
{
	bool f1=(a[0]==a[2])&&(a[5]==a[7])&&(a[2]==a[5]);
	bool f2=(a[1]==a[3])&&(a[4]==a[6])&&(a[1]==a[4]);
	return f1&&f2;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n;
	cin>>n;
    //算出年月日
	int y=n/10000;
	int m=n%10000/100;
	int d=n%100;
	bool flag1=0,flag2=0;//要打标记
	string ans1,ans2;
	while(1)//因为不知道什么时候能找到,于是直接写死循环
	{
		d++;
		if(check(y))//判断是否为闰年
		{
			mouth[2]=29;
		}
        else
		{
			mouth[2]=28;
		}
        //进位
		if(d>mouth[m])
		{
			d=1;
			m++;
			if(m>12)
			{
				y++;
				m=1;
			}
		}
        //为了输出,于是用string存起来
		string x=to_string(y*10000+m*100+d);
		if(!flag1&&ct(x))//如果回文
		{
			ans1=x;//存储答案
			flag1=1;//打上标记,避免下次继续
		}
		if(!flag2&&huiwen(x))//如果是ABABBABA结构
		{
			ans2=x;//存储答案
			flag2=1;//打上标记,避免下次继续
		}
		if(flag1&&flag2)//假如说都被找到了
		{
			break;//循环退出
		}
	}
	cout<<ans1<<'\n'<<ans2;//输出
	return 0;
}

T5.小挖的时间

题目注意点:

1.只有12个时间点,可以先除以\(60\*12=720\),这样子可以省时间,否则就会TLE。

2.这里的check函数要把个十百千都找出来,然后打三个tmp来算减去的时间

3.%720之前要把t/720*31给存进变量里

补题后代码

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int N1 = 1e3 + 2;
typedef long long ll;
typedef unsigned long long ull;
//#define int long long
//#define fo(i,n,m) for(int i=n;i<=m;i++)
bool check(int h,int m)
{
    //求出个十百千
	int g=m%10;
	int s=m/10;
	int b=h%10;
	int q=h/10;
	int tmp1=g-s,tmp2=s-b,tmp3=b-q;//求出差,看眼是否符合等差数列
	if(q==0)//如果小时只有个位数,那只能特判
	{
		if(tmp1==tmp2)
		{
			return 1;
		}
		return 0;
	}
	if(tmp1==tmp2&&tmp2==tmp3)//如果符合等差数列
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int T,t;
	cin>>T;
	while(T--)
	{
		cin>>t;
		int h=12,m=0,cnt=t/720*31;//要先存在模
		t%=720;
		for(int i=1;i<=t;i++)
		{
			m++;
            //处理进位
			if(m==60)
			{
				h++;
				m=0;
			}
			if(h==13)
			{
				h=1;
			}
            //判断这两个时间符不符合等差数列
			if(check(h,m))
			{
				++cnt;
			}
		}
		cout<<cnt<<'\n';//由于T组数据点,于是要在循环内输出
	} 
	return 0;
}

T6.2038年问题

题目注意点:

1.要开long long否则会爆int

2.闰年要每个循环都判

3.要进位时随时都要进位

代码

#include <bits/stdc++.h>
using namespace std;
#define ll long long

int mouth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool check(int x) {//闰年判断板子
	if ((x % 400 == 0) || (x % 4 == 0 && x % 100 != 0)) {
		return 1;
	}
	return 0;
}
ll t, n, year, month, day, h, m, s;
int main() {
	int T;//T组数据
	cin >> T;
	while (T--) {
		t = 1;
		cin >> n >> year >> month >> day >> h >> m >> s;
		for (int i = 1; i < n; i++) {
			t *= 2;		//每次都需要乘2
		}
		t--;//减去第一次的1
        //进位
		s += t;
		m += s / 60;
		s %= 60;
		h += m / 60;
		m %= 60;
		day += h / 24;
		h %= 24;
        //闰年
		if (check(year)) {
			mouth[2] = 29;
		} else {
			mouth[2] = 28;
		}
		while (day > mouth[month]) {	//如果时间大于月份时间
			day = day - mouth[month];
			month++;
            //进位
			if (month == 13) {
				month = 1;
				year++;
				if (check(year)) {//进位后要及时判闰年
					mouth[2] = 29;
				} else {
					mouth[2] = 28;
				}
			}
		}
		cout << year << " " << month << " " << day << " " << h << " " << m
		     << " " << s << endl;//输出
	}
	return 0;
}

5.总结

不要一直写暴力,要思考怎么才能减时间。

考试时自己多想几组HACK数据。

标签:总结,int,31,long,month,mouth,8.20,考试,define
From: https://www.cnblogs.com/basibatuo/p/18370423

相关文章

  • 常用类总结
    一、Object类概述及其构造方法1.Object类概述类层次结构的根类。所有类都直接或者间接的继承自该类。构造方法publicObject()子类的构造方法默认访问的是父类的无参构造方法。1)Object类的成员方法publicinthashCode():这个方法返回对象的哈希码值,通常用于哈希表(如Hash......
  • 平衡树总结
    平衡树刚看的时候觉得很不好评价。但它毕竟就是个数据结构,跟线段树的用途一样,都是用来维护数据。想想你刚看线段树时候的感受,是不是和现在刚看平衡树差不多。事实来看,平衡树也不复杂。本质都是二叉搜索树,只不过维护平衡的方式不一样罢了。平衡树的类型看似那么多,实际上也就学两......
  • 深度学习--时间序列预测方法总结
    时间序列预测是分析和预测一系列时间顺序数据的方法。不同的时间序列预测方法在应用中根据数据特征和目标有不同的适用性。以下是时间序列预测方法的详细总结,包括概念、原理和Python实现代码。1.简单平均法(SimpleAverageMethod)概念与原理:简单平均法是最简单的时间序列......
  • 2024.8.20
    #include<stdio.h>#include<stdio.h>#include<sys/socket.h>#include<netinet/in.h>#include<arpa/inet.h>#include<sys/types.h>#include<string.h>#include<unistd.h>#include<stdlib.h>#include......
  • 2024年“研究生科研素养提升”考试答案分享
    1、下列哪个数据库文献不包含在知网研学平台里面()。 A、期刊文献✓ B、标准 C、硕博文献 D、年鉴文献您的答案: B 参考答案: B 收藏答案解析:知网研学平台数据库文献主要包括期刊、硕博、年签、报纸、会议。2、下列选项中,不属于全文数据库的是() A、Springerlin......
  • 20240820(周二)AH股行情总结:A股三大指数收跌近1%,游戏传媒板块大涨,工行超中国移动成市值
    A股三大股指集体下挫,创业板指跌1.34%。国债期货收盘多数上涨,30年期主力合约涨0.22%。工商银行股价再创历史新高,盘中市值超过中国移动。“黑神话”概念股大涨,浙版传媒涨停,华谊兄弟涨超10%,新迅达20CM涨停。周二,A股三大指数均收跌近1%受《黑神话:悟空》大热带动,A股游戏、传媒板......
  • 2024.8.20(playbook剧本安装nginx、roles)
    一、playbook 剧本安装nginx[root@m0~]#mkdir/etc/ansible/playbook[root@m0~]#vim/etc/ansible/playbook/nginx.yml----hosts:group02remote_user:roottasks:-name:卸载httpdyum:......
  • 8月总结
    考试test20240811password:190788test20240819password:193387比赛CodeforcesRound959sponsoredbyNEAR(Div.1+Div.2)CodeforcesRound964(Div.4)CodeforcesRound966(Div.3)知识点分治刷题板板刷花专题练习(待更新)DPDS......
  • 2024 Summer_Camp 做题总结 下
    CloseVertices思路很明显,这是一道点分治题目,但有两个限制条件,考虑将两个条件排序起来,双指针找第一个条件,树状数组维护第二个条件,但是同一个子树内不能重复统计,所以将答案减去每个子树内的答案。代码#include<iostream>#include<algorithm>#defineintlonglongusingnam......
  • Hadoop学习总结
    除了HDFS和MapReduce,Hadoop生态系统还包含了许多其他强大且实用的工具和框架,它们在数据分析和处理领域中发挥了重要作用。其中,Hive、Pig和Spark是几个尤为重要的组件,它们为处理和分析大数据提供了更高层次的抽象和简化的操作流程。在这篇报告中,我将分享我对这些工具的探索与使用经......