1
//13CSP A
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
int jump;
int score = 0,cnt = 0,pre = 0;
while(true){
cin>>jump;
if(jump == 1){
if(pre == 2){
pre = 1;
cnt = 0;
}
score++;
//pre = 1;
}
else if(jump == 2){
pre = 2;
cnt ++;
score += 2*cnt;
}
else if(jump == 0)break;
}
cout<< score <<endl;
return 0;
}
//1 1 2 2 2 1 1 2 2 0
2
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
struct Ball{
int pos;
int direction;
int id;
bool operator <(const Ball &a) const{
return pos < a.pos;
}
};
bool cmp(Ball a,Ball b){
return a.id < b.id;
}
Ball ball[105];
int main(){
int n,l,t;
cin>> n >> l >> t;
for(int i = 1;i <= n;i ++){
cin>> ball[i].pos;
ball[i].direction = 1;//1 right / -1 left
ball[i].id = i;
}
sort(ball + 1,ball + n + 1);//数据增序排序
for(int i = 1;i <= t;i ++){
for(int j = 1;j <= n;j ++){
ball[j].pos += ball[j].direction;
}
/*for(int i = 1;i <= n;i ++){
cout<< ball[i].pos<< " ";
} cout<<endl;*/
for(int j = 1;j <= n;j ++){
//ball[j].pos += ball[j].direction;
if(ball[j].pos == 0)
ball[j].direction = 1;
if(ball[j].pos == l)
ball[j].direction = -1;
if(ball[j].pos == ball[j-1].pos){
//swap(ball[j].direction,ball[j-1].direction);
ball[j].direction = 1;//这里容易错的,需要注意只需要判断一遍就可以
ball[j-1].direction = -1;
}
/*f(ball[j].pos == ball[j+1].pos){//
swap(ball[j].direction,ball[j+1].direction);
}*/
}
}
sort(ball + 1,ball + n + 1,cmp);//还原成原来的顺序
for(int i = 1; i <= n;i ++){
cout<< ball[i].pos << (i==n? '\n':' ');
}
return 0;
}
/*
3 10 5
4 6 8
10 22 30
14 12 16 6 10 2 8 20 18 4
*/