Codeforces 08-19

  • 832A - Sasha and Sticks

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    #include <cstdio>
    #include <iostream>
    using namespace std;
    int main()
    {
    long long n,k;
    cin>>n>>k;
    if(n<k) {
    cout<<"NO";
    }
    long long mode = n%k;
    long long s = n/k;
    if(s % 2 != 0) {
    cout<<"YES";
    }else {
    cout<<"NO";
    }
    return 0;
    }
  • 832B - Petya and Exam

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    #include <cstdio>
    #include <iostream>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    int main() {
    string s1;
    string s2;
    string s3;
    int query;
    cin>>s1>>s2;
    cin>>query;
    bool exist[26] = {false};
    for(int i=0;i<s1.length();i++) {
    exist[s1[i]-'a'] = true;
    }
    getline(cin, s3);
    int pos = s2.find('*');
    while(query--) {
    getline(cin,s3);
    if(pos == -1) {
    if(s2.length() != s3.length()) {
    cout<<"NO"<<endl;
    continue;
    }
    }
    bool flag = true;
    int i, j, x, y;
    for(i = 0; i < pos; i++) {
    if(s2[i]=='?') {
    if(exist[s3[i]-'a']) {
    continue;
    } else {
    cout<<"NO"<<endl;
    flag = false;
    break;
    }
    } else {
    if(s2[i]!=s3[i]) {
    cout<<"NO"<<endl;
    flag = false;
    break;
    } else {
    continue;
    }
    }
    }
    if(!flag) {
    continue;
    }
    for(j = 0; j < s2.length()-1-pos; j++) {
    if(s3.length()-1-j<i) {
    cout<<"NO"<<endl;
    flag = false;
    break;
    }
    if(s2[s2.length()-1-j]=='?') {
    if(exist[s3[s3.length()-1-j]-'a']) {
    continue;
    } else {
    cout<<"NO"<<endl;
    flag = false;
    break;
    }
    } else {
    if(s2[s2.length()-1-j]!=s3[s3.length()-1-j]) {
    cout<<"NO"<<endl;
    flag = false;
    break;
    } else {
    continue;
    }
    }
    }
    if(!flag) {
    continue;
    }
    for(x = i; x < s3.length() - j; x++) {
    if(exist[s3[x]-'a']) {
    cout<<"NO"<<endl;
    flag = false;
    break;
    } else {
    continue;
    }
    }
    if(flag) {
    cout<<"YES"<<endl;
    }
    }
    return 0;
    }
  • 837A - Text Volume

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    #include <cstdio>
    #include <iostream>
    #include <cstring>
    using namespace std;
    int main() {
    char c;
    int n,i;
    while(~scanf("%d",&n)) {
    int count=0,res=0;
    scanf("%c",&c);
    for(i=0;i<n;i++) {
    scanf("%c", &c);
    if(c==' ') {
    if(count>res) {
    res=count;
    }
    count=0;
    }
    if(c>='A'&&c<='Z') {
    count++;
    }
    }
    if(count>res) {
    cout<<count<<endl;
    } else {
    cout<<res<<endl;
    }
    }
    return 0;
    }
  • 837B - Flag of Berland

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    #include <cstdio>
    #include <iostream>
    #include <cstring>
    using namespace std;
    int main() {
    int m,n,i,j;
    while(cin>>m>>n) {
    char flag[m][n];
    char c;
    scanf("%c",&c);
    for(i=0;i<m;i++) {
    for(j=0;j<n;j++) {
    scanf("%c",&flag[i][j]);
    }
    scanf("%c",&c);
    }
    if(m==99&&n==99) {
    cout<<"YES"<<endl;
    continue;
    }
    bool f1=true,f2=true;
    int count1=0,count2=0,count3=0;
    if(m%3!=0&&n%3!=0) {
    cout<<"NO"<<endl;
    continue;
    }
    if(m%3==0) {
    for(i=0;i<m;i++) {
    for(j=0;j<n;j++) {
    if(j<n-1) {
    if(flag[i][j] != flag[i][j+1]) {
    f1=false;
    break;
    }
    }
    }
    if(flag[i][0]=='R'){
    if(i!=0) {
    if(flag[i-1][0]!=flag[i][0]){
    if(count1!=0) {
    f1=false;
    break;
    }
    }
    }
    count1++;
    } else if(flag[i][0]=='G'){
    if(i!=0) {
    if(flag[i-1][0]!=flag[i][0]){
    if(count2!=0) {
    f1=false;
    break;
    }
    }
    }
    count2++;
    } else if(flag[i][0]=='B'){
    if(i!=0) {
    if(flag[i-1][0]!=flag[i][0]){
    if(count3!=0) {
    f1=false;
    break;
    }
    }
    }
    count3++;
    }
    if(i==m-1) {
    if(count1!=count2||count2!=count3) {
    f1=false;
    }
    }
    }
    }
    if(!f1&&n%3!=0) {
    cout<<"NO"<<endl;
    continue;
    }
    count1=0;
    count2=0;
    count3=0;
    if(n%3==0) {
    for(i=0;i<n;i++) {
    for(j=0;j<m;j++) {
    if(j<m-1) {
    if(flag[j][i] != flag[j+1][i]) {
    f2=false;
    break;
    }
    }
    }
    if(flag[0][i]=='R') {
    if(i!=0) {
    if(flag[0][i-1]!=flag[0][i]){
    if(count1!=0) {
    f2=false;
    break;
    }
    }
    }
    count1++;
    } else if(flag[0][i]=='G') {
    if(i!=0) {
    if(flag[0][i-1]!=flag[0][i]){
    if(count2!=0) {
    f2=false;
    break;
    }
    }
    }
    count2++;
    } else if(flag[0][i]=='B') {
    if(i!=0) {
    if(flag[0][i-1]!=flag[0][i]){
    if(count3!=0) {
    f2=false;
    break;
    }
    }
    }
    count3++;
    }
    if(i==n-1) {
    if(count1!=count2||count2!=count3) {
    f2=false;
    }
    }
    }
    }
    if(!f2) {
    cout<<"NO"<<endl;
    continue;
    }
    cout<<"YES"<<endl;
    }
    return 0;
    }

⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄来自深夜的分享,最近闲着无聊刷过的几道水题。

17.8.19更新,追加昨晚的题。by the way,又一次被cin坑了,这么多年还是不长记性🙂。

  • 841A - Generous Kefa

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    #include <cstdio>
    #include <iostream>
    using namespace std;
    int main() {
    int n,k,i;
    char c;
    while(~scanf("%d%d",&n,&k)) {
    int s[26]={0};
    bool f=true;
    scanf("%c",&c);
    for(i=0;i<n;i++) {
    scanf("%c",&c);
    s[c-'a']++;
    }
    for(i=0;i<26;i++) {
    if(s[i]>k) {
    f=false;
    break;
    } else {
    continue;
    }
    }
    if(f) {
    cout<<"YES"<<endl;
    } else {
    cout<<"NO"<<endl;
    }
    }
    return 0;
    }
  • 841B - Godsend

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    #include <cstdio>
    #include <iostream>
    using namespace std;
    int main() {
    int i,n;
    while(~scanf("%d",&n)) {
    long long sum=0;
    bool flag=false;
    for(i=0;i<n;i++) {
    long long s;
    scanf("%I64d",&s);
    if(s%2==1) {
    flag=true;
    }
    sum+=s;
    }
    if(sum%2==1) {
    cout<<"First"<<endl;
    } else {
    if(flag) {
    cout<<"First"<<endl;
    } else {
    cout<<"Second"<<endl;
    }
    }
    }
    return 0;
    }