本文共 1403 字,大约阅读时间需要 4 分钟。
#include#include #include #include #include #include #include using namespace std;typedef long long ll;int a[1100];int main(){ int t; cin>>t; int n,k,sum=0; while(t--){ cin>>n>>k; sum=0; memset(a,0,sizeof(a)); for(int i=n;i>=1;i--){ if((i>k||(i>=(k+1)/2))&&i!=k){ a[i]=1; sum++; } } cout< <
题意:在星球 Lapituletti 上定义一天有h个小时,每小时m分钟。现在给一个时间,如果他在镜像中也是有效的的就输出这个时间,如果他在镜像中不是有效的,找出未来最接近它的一个时间。(如果时间由0、1、2、5、8中几个数字构成,且镜像中小时<h和分钟<m,则有效) 题解:模拟,先判断是不是是由0、1、2、5、8中的几个数字构成,在判断是不是在规定范围内,如果合法输出,不合法再在给出的时间的基础上依次增大寻找 代码:
#include#include #include #include #include #include #include #include using namespace std;typedef long long ll;int a[1100];bool check(string s){ for(int i=0;i >t; int h,m; string s1,s2; while(t--){ int flag=0; int ah=0,am=0; int fh=0,fm=0; cin>>h>>m; cin>>s1; if(check(s1)){ s2=change(s1); ah=(s2[4]-'0')*10+(s2[3]-'0'); am=(s2[1]-'0')*10+(s2[0]-'0'); flag=1; } string s,ts; fh=(s1[0]-'0')*10+(s1[1]-'0'); fm=(s1[3]-'0')*10+(s1[4]-'0'); if(flag&&ah =10){ s="0"+to_string(i)+":"+to_string(j); }else if(i>=10&&j<10){ s=to_string(i)+":0"+to_string(j); }else if(i<10&&j<10){ s="0"+to_string(i)+":0"+to_string(j); }else{ s=to_string(i)+":"+to_string(j); } if(check(s)){ ts=change(s); ah=(ts[4]-'0')*10+(ts[3]-'0'); am=(ts[1]-'0')*10+(ts[0]-'0'); if(ah
转载地址:http://ppnki.baihongyu.com/