代补知识点:
字符串分割、并查集、高精度、搜索、STL基础、高级数据结构(树状数组2014年第十题)、string进阶
判断闰年
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,year=1777,month=4,day=29;
int a[15]={0,31,28,31,30,31,30,31,31,30,31,30,31};
cin >> n;
//for(int i = 1;i <= 12;i++)cout << a[i] <<endl;
while(n--){
day++;
if((year % 4 == 0&&year % 100 != 0)||(year % 100 == 0 && year % 400 == 0)){
if(month==2){
if(day == 29)continue;
if(day > 29) {
day = 1;
month=3;
}
}
}
if (day > a[month]){
day = 1;
month++;
if(month > 12)month = 1,year++;
}
}
cout << year <<endl << month << endl << day <<endl;
return 0;
}
//1799 7 16
/
递归
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,year=1777,month=4,day=29,ans=0;
void dfs(int step , int cnt){
if(cnt>=39){
if(step%2==0&&cnt==39)ans++;
return ;
}
dfs(step+1,cnt+1);
dfs(step+1,cnt+2);
return ;
}
int main(){
dfs(0,0);
cout << ans <<endl;
//for(int i = 1;i <= 12;i++)cout << a[i] <<endl;
//cout << year <<endl << month << endl << day <<endl;
return 0;
//51167078
}
妙蛙种子进了米奇妙妙屋,妙到家了
问题描述
小明这些天一直在思考这样一个奇怪而有趣的问题:
在1~N的某个全排列中有多少个连号区间呢?这里所说的连号区间的定义是:
如果区间[L, R] 里的所有元素(即此排列的第L个到第R个元素)递增排序后能得到一个长度为R-L+1的“连续”数列,则称这个区间连号区间。
当N很小的时候,小明可以很快地算出答案,但是当N变大的时候,问题就不是那么简单了,现在小明需要你的帮助。
输入格式
第一行是一个正整数N (1 <= N <= 50000), 表示全排列的规模。
第二行是N个不同的数字Pi(1 <= Pi <= N), 表示这N个数字的某一全排列。
输出格式
输出一个整数,表示不同连号区间的数目。
样例输入1
4
3 2 4 1
样例输出1
7
样例输入2
5
3 4 2 5 1
样例输出2
9
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[50005],mn=100005,cnt,b[200],q,d,big,small,ans;
int main(){
cin >> n;
for(int i = 1;i <= n;i++)cin >> a[i];
for(int i = 1;i <= n;i++){
int big = a[i],small = a[i];
for(int j = i;j <= n;j++){
if(a[j]>big)big = a[j];
if(a[j]<small)small = a[j];
if(j-i==big-small)ans++;
}
}
cout << ans << endl;
return 0;
}
字符串的神仙操作(字符串流)
#include<cstdio>
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
using namespace std;
void i2s(int num,string &str){
stringstream ss;
ss << num;
ss >> str;
}
int main(){
int ans = 0;
for(int i = 10000;i <= 99999;i++){
string s;
i2s(i,s);
if(s.find('4')==string::npos)ans++;
}
cout << ans << endl;
return 0;
}