10.8改错

· · 个人记录

国庆day2李晨轩改错

1.slime史莱姆

题目描述

下达指令让所有的史莱姆同时做以下移动:上 下 左 右 。使得至少一个史莱姆到达了左上角格子并且所有史莱姆 未发生消散。

解题思路

可以获取第一个史莱姆到边缘的距离,判断地图上有没有史莱姆的x小于它。

错误原因

~想复杂了!~ ~~ :::success[AC Code]

#include<bits/stdc++.h>
using namespace std;
int t, n, m;
char ch[105][105];
int main() {
//  freopen("slime.in","r",stdin);
//  freopen("slime.out","w",stdout);
    cin >> t;
    while (t--) {
        int flag = 0;
        cin >> n >> m;
        int my;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                cin >> ch[i][j];
            }
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (ch[i][j] == 'S') {
                    my = j;
                    flag=1;
                    break;
                }
            }
            if(flag){
                break;
            }
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (ch[i][j] == 'S') {
                    if (j < my) {
                        flag = 0;
                        break;
                    }
                }
            }
            if(flag==0){
                break;
            }
        }
        if(flag){
            cout << "YES" << endl;  
        }else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

:::

2.rune符文石

题目描述

在古老的符文圣殿中,存放着 块蕴含神秘力量的符文石。第 块符文石需要注入 单位能量才能激活。大祭司有两种注入能量的方式:\ 一、凝聚符文\ 二、圣能迸发\ 每次凝聚符文或圣能迸发均视为一次操作。初始圣能点数为 ,请求出激活所有符文石的最少操作次数。

解题思路

贪心思想!!!\ 用圣能从小到大激活,圣能不够激活的符文石便一点一点相加,记录总操作次数即可。

错误原因

~骗分10分~😓😓😓 :::success[AC Code]

#include<bits/stdc++.h>
using namespace std;
long long n, a[200005], ans, s;
int main() {
//  freopen("rune.in","r",stdin);
//  freopen("rune.out","w",stdout);
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        s += a[i];
    }
    sort(a + 1, a + 1 + n);
    if(s%2==1){
        s=s/2+1;
    }else{
        s/=2;
    }
    long long x=0;
    for (int i = 1; i <= n; i++) {
        if (x+a[i] <= s) {
            x+=a[i];
            ans += a[i];
        } else {
            ans += s-x;
            cout<<ans +(n-i+1);
            return 0;
        }
    }
    return 0;
}

:::

3.roll蛋糕卷

题目描述

帮蛋糕师小爱找出这条蛋糕卷上最精致的连续段的长度。

解题思路

用同向双指针 如果区间和小于 S 则向右移动右指针 ,大于或等于则记录答案的最小值,并向右移动左指针 。\ (ps:数据范围 1e7 记得读入优化。)

错误原因

~对双指针不太熟练~ :::success[AC Code]

#include<bits/stdc++.h>
using namespace std;
long long n,s,sum,ans=1e9;
long long a[10000005];
long long ss[10000005];
int read() {
    int x = 0, f = 1;   
    char ch = getchar();    
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;    
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';      
        ch = getchar();
    }
    return x * f;                 
}
int main(){
    n=read();
    s=read();
    for(int i=1;i<=n;i++){
        a[i]=read();
        ss[i] = ss[i -1] + a[i];
    }
    long long l=1,r=2;
    while(l<=n&&r<=n){
        sum = ss[r] - ss[l - 1];
        if(sum<s){
            r++;
        }
        if(sum>=s){
            sum=0;
            ans=min(ans,r-l+1);
//          cout<<l<<" "<<r<<endl;
            l++;
        }
    }
    cout<<ans;
    return 0;
}

:::

4.julian儒略历

题目描述

正整数n代表公元1年1月1日后的n天。按照 "日月年" 的格式输出数据,日月年之间隔一个空格。月份按照对应大写字母输出。

解题思路

进行模拟。判断是否是闰年。

错误原因

~骗分30分~ :::success[AC Code]

#include<bits/stdc++.h>
using namespace std;
int r;
bool isLeap(int y) {
    if (y <= 1582) {
        return y % 4 == 0;
    } else {
        return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0);
    }
}
int year(int y){
    if(y==1582) return 355;
    if(isLeap(y)) return 366;
    else return 365;
}
int months(int n,int y){
    if(n==1582&&y==10) return 21;
    if(y==1||y==3||y==5||y==7||y==8||y==10||y==12) return 31;
    if(y==4||y==6||y==9||y==11) return 30;
    if(y==2){
        if(isLeap(n)){
            return 29;
        }else{
            return 28;
        }
    }
}
string t[]={"0"," JAN "," FEB "," MAR "," APR "," MAY "," JUN "," JUL "," AUG "," SEP "," OCT "," NOV "," DEC "};
int main() {
    cin >> r;
    r++;
    int n=1,y=1;
    while(r>=year(n)){
        r-=year(n);
        n++;
    }
    while(r>=months(n,y)){
        r-= months(n,y);
        y++;
    }
    cout<<r<<t[y]<<n;
    return 0;
}

:::

5.chess西洋棋

题目描述

在所有可能从左上角走到右下角的路径中,哪一条路径能让她收集到的格子权值总和达到最大?并且,她还想知道,这样的“最优路径”总共有多少条?

解题思路

比较简单的坐标DP。

:::