简单模拟即可
#include#define ll long long using namespace std; int p1,p2,p3; string s; vector ans; void rep(char l,char r){ ans.push_back(l); if(r<=l){ans.push_back('-');} else if(r==l+1){} else {//l-r if(p1==1 && p3==1){ for(char i=l+1;i<=r-1;i++) for(int k=0;k =l+1;i--) for(int k=0;k =l+1;i--) for(int k=0;k >p1>>p2>>p3>>s; int len=s.size(); for(int i=0;i
B-[NOIP2017]时间复杂度2
C-[NOIP2010]机器翻译注意这里cnt不但可以记录个数,模m后表示字典中下一个要被删除的单词
#includeusing namespace std; int dict[110],pas[1010]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int m,n,cnt=0; cin>>m>>n; for(int i=0;i >pas[i]; for(int i=0;i
D-四舍五入4
E-安卓图案解锁1.判断是否重复出现
2.判断是否跳过数字(将横竖斜都判断一遍)
3.将一些边的判断合并,如经过5的,然后(9,1)(3,7)配对判断
ps:详细看代码,结合图理解
#includeusing namespace std; int main(){ string s1; while(cin>>s1){ vector dict,s; bool check=1; for(int i=0;i
F- 从后台研发到跑路2
G-回文数1.注意前导0(00也算,0不算)(要出现前导0,有且仅有2种数字出现,并且非0的数字只有1个)
2.数量为奇数个的数不超过1个
#includeusing namespace std; int a[10]; bool check1=1,check2=0,check=1; vector ans; int main(){ for(int i=0;i<10;i++)cin>>a[i]; int cnt=0;//记录奇数个的数的个数 for(int i=0;i<10;i++){if(a[i]&1) cnt++;} if(cnt>1)check=false; if(a[0]>=2){ int sum=0; for(int i=0;i<10;i++){sum+=a[i];} if(a[0]+1==sum || a[0]==sum){ printf("-1"); return 0; } } if(check){ int ji=-1; for(int i=0;i<10;i++)if(a[i]&1){ji=i;break;} for(int i=1;i<10;i++){ if(a[i]>=2){ ans.push_back(i); a[i]-=2; break; } } for(int i=0;i<10;i++){ while(a[i]>=2)ans.push_back(i),a[i]-=2; } for(int i=0;i=0;i--)cout<
H-回文数1
I-[NOIP2016]玩具谜题1
J-[NOIP2015]神奇的幻方按题目所给条件模拟即可
#includeusing namespace std; int n; int a[40][40]; pair pos;//记录上一个点的位置 int main(){ cin>>n; a[1][(1+n)/2]=1; pos={1,(1+n)/2}; for(int i=2;i<=n*n;i++){ if(pos.first==1 && pos.second!=n){ a[n][pos.second+1]=i; pos={n,pos.second+1}; } else if(pos.second==n && pos.first!=1){ a[pos.first-1][1]=i; pos={pos.first-1,1}; } else if(pos.first==1 && pos.second==n){ a[pos.first+1][pos.second]=i; pos={pos.first+1,pos.second}; } else { if(a[pos.first-1][pos.second+1]==0){ a[pos.first-1][pos.second+1]=i; pos={pos.first-1,pos.second+1}; } else { a[pos.first+1][pos.second]=i; pos={pos.first+1,pos.second}; } } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cout<
K-Tic-tac-toe5
L-I love youdp比较难想到,想到之后挺简单的
#includeusing namespace std; char ch; int dp[8];//表示前i个字符在字符串中出现了dp[i]次 const int p=20010905; int main(){ string s; cin>>s; for(int i=0;i
M-[NOIP2016]回文日期分解题目:
1.回文函数 2.找到下一个日期 3.闰年判断(当然可以和2合并)
#includeusing namespace std; const int run_mon[]={0,31,29,31,30,31,30,31,31,30,31,30,31}; const int mon[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; inline bool run(int year){ if(year%4==0 &&(year%100!=0 || year%400==0)) return true; return false; } inline bool huiwen(int date){ vector s; while(date>0){ s.push_back(date%10); date/=10; } for(int i=0;i<=(int)s.size()/2;i++){ if(s[i]!=s[s.size()-1-i])return false; } return true; } inline int next_date(int date){ int year,month,day; year=date/10000; month=date/100%100; day=date%100; if(run(year)){ day++; if(day>run_mon[month]){day=1; month++;}; if(month>12){month=1,year++;}; } else { day++; if(day>mon[month]){day=1; month++;}; if(month>12){month=1,year++;}; } return year*10000+month*100+day; } int main(){ int l,r,cnt=0; cin>>l>>r; if(huiwen(l))cnt++; while(next_date(l)<=r){ l=next_date(l); if(huiwen(l))cnt++; } cout<
N-校门外的树签到
#includeusing namespace std; bool tree[10010]; int cnt,l,r,L,M; int main(){ cin>>L>>M; for(int i=0;i >l>>r; for(int j=l;j<=r;j++)tree[j]=1; } for(int i=0;i<=L;i++){ if(tree[i]==0)cnt++; } cout<
O-值周首先考虑算法可行性:考虑n的规模,时间复杂度要小于nlgn(可以用sort了)
思路:排序后合并区间(见下图)
两个区间有交集的时候,合并成大区间;不然则开辟新区间,并将上一个区间的人赶走
#include#define ll long long using namespace std; vector< pair > tree; int cnt,L,M,l,r,len; bool cmp(pair a,pair b){ return a.first<=b.first; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>L>>M; int x,y; for(int j=0;j >x>>y; tree.push_back({x,y}); } sort(tree.begin(),tree.end(),cmp); l=tree[0].first,r=tree[0].second; for(int i=1;i r+1){ len+=r-l+1; // cout<
P-货物种类1
Q-储物点的距离2
R-糖糖别胡说,我真的不是签到题5



