B. Falling Apples 题解(2016 ICPC Mid-Central USA Region)

本文详细解读了2016年ICPC中部美国赛区的‘Falling Apples’题目,探讨如何解决苹果不能向下掉落,使其到达最低位置的算法策略。
INPUT
3 3 
aaa
#.. 
..#
OUTPUT
a..
#.a 
.a#

INPUT
4 5 
aaa.a 
aa.a.
a.a.. 
...a.
OUTPUT
.....
a.... 
aaaa.
aaaaa

题意:落苹果,#不能往下落,让a落到最低。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
const int mod=1e9+10;
const int M=5e4 + 10;
char mapp[M][15];
int vis[M][15];
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1; i<=n; i++)
    {
        scanf("%s",mapp[i]);
    }
    for(int j=0; j<m; j++)
    {
        int sum=0;
        for(int i=1; i<=n; i++)
        {
            if(mapp[i][j] == 'a')
                sum++;
            if(mapp[i][j] == '#')
            {
                vis[i][j] = 2;
                for(int k=i-1; k>=1; k--)
                {
                    if(sum == 0)
                        break;
                    else
                        vis[k][j] = 1,sum--;
                }
            }
        }
        for(int k=n; k>=1; k--)
        {
            if(sum == 0)
                break;
            else
                vis[k][j]=1,sum--;
        }
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=0; j<m; j++)
        {
            if(vis[i][j] == 2)
                printf("#");
            else if(vis[i][j] == 1)
                printf("a");
            else
                printf(".");
        }
        printf("\n");
    }
    return 0;
}

 

. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.5.9) 2025-03-29 23:30:44.927 INFO 10080 --- [ main] com.example.SpringbootApplication : Starting SpringbootApplication using Java 1.8.0_341 on DESKTOP-EUNUR1G with PID 10080 (D:\毕业设计\manager\springboot\target\classes started by DELL in D:\毕业设计\manager) 2025-03-29 23:30:44.929 INFO 10080 --- [ main] com.example.SpringbootApplication : No active profile set, falling back to default profiles: default 2025-03-29 23:30:45.709 INFO 10080 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9090 (http) 2025-03-29 23:30:45.716 INFO 10080 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2025-03-29 23:30:45.716 INFO 10080 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56] 2025-03-29 23:30:45.800 INFO 10080 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2025-03-29 23:30:45.800 INFO 10080 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 836 ms Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter. Parsed mapper file: 'file [D:\毕业设计\manager\springboot\target\classes\mapper\AdminMapper.xml]' Parsed mapper file: 'file [D:\毕业设计\manager\springboot\target\classes\mapper\NoticeMapper.xml]' ,------. ,--. ,--. ,--. | .--. ' ,--,--. ,---. ,---. | '--' | ,---. | | ,---. ,---. ,--.--. | '--' | ' ,-. | | .-. | | .-. : | .--. | | .-. : | | | .-. | | .-. : | .--' | | -
最新发布
03-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值