#include<iostream>usingnamespace std;int a[100000];//a[0],a[n+1]=0;intmain(){int n;scanf("%d",&n);for(int i =1;i <= n;++i)scanf("%d",&a[i]);for(int i =1;i <= n;++i){int ans = a[i-1]+ a[i]+ a[i+1];(i ==1||i == n)?printf("%d ",ans /2):printf("%d ",ans /3);}return0;}
8
4 1 3 1 6 5 17 9
2 2 1 3 4 9 10 13
2. 买菜
//简单模拟,hash方法,暴力方法#include<iostream>usingnamespace std;constint N=1000005;intmain(){int n, x, y, flag[N]={0};longlong ans =0;scanf("%d",&n);for(int i =1;i <=2*n;i++){scanf("%d%d",&x,&y);for(int j = x;j < y;j++)
flag[j]++;}for(int i =1;i < N;i++){if(flag[i]==2)
ans++;}printf("%lld\n", ans);return0;}
4
1 3
5 6
9 13
14 15
2 4
5 7
10 11
13 14
3
3. 元素选择器
#include<iostream>#include<string>#include<sstream>#include<vector>#include<algorithm>usingnamespace std;constint MAXN =105;struct Selector{int row;int rank;
string label;//html,head,title,body,h1,p,div
string id;//#property};
Selector html[MAXN];intmain(){int n,m;scanf("%d%d",&n,&m);getchar();for(int i =1;i <= n;++i){
string ht, str;int num =0;getline(cin, ht);
istringstream ss(ht);
ss >> str;//"."while(str[num]=='.') num++;
html[i].row = i;
html[i].rank = num /2;
html[i].label = str.substr(num);//Labels are not case sensitivetransform(html[i].label.begin(), html[i].label.end(), html[i].label.begin(),::tolower);//Get id propertywhile(ss >> str){if(str[0]=='#')
html[i].id = str;}}//for endfor(int i =0;i < m;++i){
string line, str;
vector<string> query;int cnt =0, num, flag[MAXN];getline(cin, line);
istringstream ss(line);while(ss >> str){if(str[0]!='#'){//Labels are not case sensitivetransform(str.begin(),str.end(),str.begin(),::tolower);}
query.push_back(str);//Store query keywords.For example,(div div p)}//Compare from back to front
vector<string>::reverse_iterator it = query.rbegin();for(int j =1;j <= n;++j){if(html[j].id ==*it || html[j].label ==*it)//The last query keyword(div div p:p)
flag[cnt++]= j;//Record all possible line id}
num = cnt;//Record total number of possible lines//Up to (cnt) lines to meet the conditions, continue to comparefor(int k =0;k < cnt;++k){//Judge one by one
it = query.rbegin()+1;//(div div p:div)int mrank = html[flag[k]].rank;for(int j = flag[k]-1;it != query.rend()&& j >0;--j){if(html[j].rank < mrank &&(*it == html[j].label ||*it == html[j].id)){++it;
mrank = html[j].rank;}}if(it != query.rend()){
flag[k]=0;
num--;}}
cout << num;//total number of linesfor(int j =0;j < cnt;++j){if(flag[j]) cout <<" "<< flag[j];}
cout << endl;}//for endreturn0;}
11 5
html
..head
....title
..body
....h1
....p #subtitle
....div #main
......h2
......p #one
......div
........p #two
p
#subtitle
h3
div p
div div p
3 6 9 11
1 6
0
2 9 11
1 11