Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A B C D 模拟



链接:戳这里


A. Little Artem and Presents
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that.

How many times can Artem give presents to Masha?

Input
The only line of the input contains a single integer n (1 ≤ n ≤ 109) — number of stones Artem received on his birthday.

Output
Print the maximum possible number of times Artem can give presents to Masha.

Examples
input
1
output
1
input
2
output
1
input
3
output
2
input
4
output
3
Note
In the first sample, Artem can only give 1 stone to Masha.

In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.


In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.

In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.

代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
int n;
int main(){
    scanf("%d",&n);
    int num=n/3*2;
    if(n%3) num++;
    cout<<num<<endl;
    return 0;
}



B. Little Artem and Grasshopper
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.

The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.

Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.

Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.

Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).

Examples
input
2
><
1 2
output
FINITE
input
3
>><
2 1 1
output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.

Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.


题意:给出n个字符和n个权值,'>'表示蚂蟥踩到这个点可以向右条x[i]格  '<'向左跳x[i]格
如果跳出了范围,输出FINITE ,如果一直可以跳  ,输出INFINITE


代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
int n;
int a[1000100];
string s;
map<int,int> mp;
int main(){
    scanf("%d",&n);
    cin>>s;
    for(int i=0;i<n;i++) {
        scanf("%d",&a[i]);
        mp[i]=0;
    }
    int x=0,flag=0;
    while(x>=0 && x<n){
        ///cout<<x<<endl;
        if(mp[x]==1) {
            flag=1;
            break;
        }
        if(s[x]=='>'){
            mp[x]=1;
            x+=a[x];
        } else {
            mp[x]=1;
            x-=a[x];
        }
    }
    if(flag) cout<<"INFINITE"<<endl;
    else cout<<"FINITE"<<endl;
    return 0;
}


C. Little Artem and Matrix
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.

That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.

Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.

Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.

Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.

Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m,  - 109 ≤ xi ≤ 109) are given.

Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.

Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.

If there are multiple valid solutions, output any of them.

Examples
input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
output
8 2 
1 8 
input
3 3 2
1 2
3 2 2 5
output
0 0 0 
0 0 5 
0 0 0 


题意:

给出n*m的矩阵和q个操作

1  r表示第r行的元素依次向左滑一格

2  c表示第c列的元素依次向上滑一格

3 r c x表示第r行c列的元素当前的值为 x

要求你给出满足条件的原始矩阵


思路:倒着模拟回去就可以了


代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
int n,m,q;
int a[1010][1010];
int t[10100],r[10100],c[10100],x[10100];
int main(){
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=q;i++){
        scanf("%d",&t[i]);
        if(t[i]==1) scanf("%d",&r[i]);
        else if(t[i]==2) scanf("%d",&c[i]);
        else scanf("%d%d%d",&r[i],&c[i],&x[i]);
    }
    for(int i=q;i>=1;i--){
        if(t[i]==3) a[r[i]][c[i]]=x[i];
        else if(t[i]==1){
            int tmp=a[r[i]][m];
            for(int j=m;j>=2;j--) a[r[i]][j]=a[r[i]][j-1];
            a[r[i]][1]=tmp;
        } else {
            int tmp=a[n][c[i]];
            for(int j=n;j>=2;j--) a[j][c[i]]=a[j-1][c[i]];
            a[1][c[i]]=tmp;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            printf("%d ",a[i][j]);
        }
        cout<<endl;
    }
    return 0;
}


D. Little Artem and Dance
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.

More detailed, there are n pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a girl number 2 and so on. Girls are numbered in the clockwise order. During the dance different moves are announced and all pairs perform this moves. While performing moves boys move along the circle, while girls always stay at their initial position. For the purpose of this problem we consider two different types of moves:

Value x and some direction are announced, and all boys move x positions in the corresponding direction.
Boys dancing with even-indexed girls swap positions with boys who are dancing with odd-indexed girls. That is the one who was dancing with the girl 1 swaps with the one who was dancing with the girl number 2, while the one who was dancing with girl number 3 swaps with the one who was dancing with the girl number 4 and so one. It's guaranteed that n is even.
Your task is to determine the final position of each boy.

Input
The first line of the input contains two integers n and q (2 ≤ n ≤ 1 000 000, 1 ≤ q ≤ 2 000 000) — the number of couples in the rueda and the number of commands to perform, respectively. It's guaranteed that n is even.

Next q lines contain the descriptions of the commands. Each command has type as the integer 1 or 2 first. Command of the first type is given as x ( - n ≤ x ≤ n), where 0 ≤ x ≤ n means all boys moves x girls in clockwise direction, while  - x means all boys move x positions in counter-clockwise direction. There is no other input for commands of the second type.

Output
Output n integers, the i-th of them should be equal to the index of boy the i-th girl is dancing with after performing all q moves.

Examples
input
6 3
1 2
2
1 2
output
4 3 6 5 2 1
input
2 3
1 1
2
1 -2
output
1 2
input
4 2
2
1 3
output
1 4 3 2


题意:n对情侣围成一圈在跳舞,给出q个操作,表示男生的移动操作

1 x   x为负数表示所有的男生逆时针走x步  x为正数表示所有的男生顺时针走x步

2     表示当前的男生相对奇偶交换顺序  比如swap(1,2)    swap(3,4)  而不能sawp(2,3)


思路:x为负数时变成顺时针走x+n步

可以发现所有的奇数位置男生都是移动相同的步数ans1

所有的偶数位置的男生也是移动相同的步数  ans2

枚举1位置的男生的移动步数和2位置的男生移动步数即可求出答案

1位置的男生

当前的ans为奇数     ans+=x   若前面操作2交换了奇数次  则ans++   否则ans--

当前的ans为偶数     ans+=x   若前面操作2交换了奇数次 则 ans++  否则 ans--


2位置的男生

当前的ans2为奇数     ans2+=x   若前面操作2交换了奇数次  则ans2++   否则ans2--

当前的ans2为偶数     ans2+=x   若前面操作2交换了奇数次 则 ans2++  否则 ans2--


代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
int n,q;
int type[2000100];
ll x[2000100],anw[2000100];
int main(){
    scanf("%d%d",&n,&q);
    for(int i=1;i<=q;i++){
        scanf("%d",&type[i]);
        if(type[i]==1) {
            scanf("%I64d",&x[i]);
            if(x[i]<0) x[i]+=n;
        }
        else x[i]=x[i-1];
    }
    ll num=0,ans=1;
    for(int i=1;i<=q;i++){
        if(type[i]==1){
            if(num && num%2){
                if(ans%2==1) ans++;
                else ans--;
            }
            ans+=x[i];
            num=0;
        } else num++;
    }
    if(num && num%2){
        if(ans%2==1) ans++;
        else ans--;
    }
    ans--;
    num=0;

    ll ans2=2;
    for(int i=1;i<=q;i++){
        if(type[i]==1){
            if(num && num%2){
                if(ans2%2==1) ans2++;
                else ans2--;
            }
            ans2+=x[i];
            num=0;
        } else num++;
    }
    if(num&& num%2){
        if(ans2%2==1) ans2++;
        else ans2--;
    }
    num=0;

    ans2-=2;

    int t;
    for(int i=1;i<=n;i++){
        if(i%2) t=(i+ans+n)%n;
        else t=(i+ans2+n)%n;
        if(t==0) anw[n]=i;
        else anw[t]=i;
    }
    for(int i=1;i<=n;i++) printf("%I64d ",anw[i]);
    cout<<endl;
    return 0;
}<strong>
</strong>


1位置的男生

当前的ans为奇数     ans+=x   若前面操作2交换了奇数次  则ans++   否则ans--

当前的ans为偶数     ans+=x   若前面操作2交换了奇数次 则 ans2++  否则 ans2--

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值