Ifter Party LightOJ - 1014(水题)

本文介绍了一种通过遍历和使用集合存储结果的方法来解决特定的食物分配问题。具体而言,对于给定的食物总数和个人剩余的食物数量,算法可以找出每个人可能消费的食物数量的所有可能性,并按升序输出这些可能性。
题意:有C个人,给P个食物,每人吃Q个,剩L个。然后给你P和L(Q>L),让你求Q的可能情况,如果有多种可能,从小到大输出;如果不存在,输出impossible

就是求写出公式 遍历c求P-L的因子就出来了

用set 正好

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 10010, INF = 0x7fffffff;
set<LL> s;
int main()
{
    int T, kase = 0;
    scanf("%d",&T);
    while(T--)
    {
        s.clear();
        LL p, l;
        scanf("%lld%lld",&p,&l);
        for(LL i=1; i * i<=p-l; i++)
            if((p-l)%i == 0)
            {
                if(i > l)
                    s.insert(i);
                if((p-l)/i > l)
                    s.insert((p-l)/i);
            }

        printf("Case %d:",++kase);
        if(s.empty())
            printf(" impossible");
        else
            for(set<LL>::iterator it = s.begin(); it!=s.end(); it++)
            {
                printf(" ");
                printf("%lld",*it);
            }
        printf("\n");
    }


    return 0;
}

 

题意:有C个人,给P个食物,每人吃Q个,剩L个。然后给你P和L(Q>L),让你求Q的可能情况,如果有多种可能,从小到大输出;如果不存在,输出impossible

转载于:https://www.cnblogs.com/WTSRUVF/p/9341686.html

set APPL=230429 set CoordName=LamCon_40N_97W set GridName=2023_04SE1 set CMAQ_HOME = /student/home/wsj123/1/CMAQ set DataPath = /student/home/wsj123/1/CMAQ/data set InMetDir = /student/home/wsj123/1/CMAQ/wrfout set IfGeo = T set InGeoDir = /student/home/wsj123/1/CMAQ/wps_geo set InGeoFile = ( /student/home/wsj123/1/CMAQ/wps_geo/geo_em.d01.nc ) set OutDir = /student/home/wsj123/1/CMAQ/cmaq5.3.1/CMAQ-CMAQv5.3.1_19Dec2019/PREP/mcip/output set ProgDir = /student/home/wsj123/1/CMAQ/cmaq5.3.1/CMAQ-CMAQv5.3.1_19Dec2019/PREP/mcip/src set WorkDir = /student/home/wsj123/1/CMAQ/cmaq5.3.1/CMAQ-CMAQv5.3.1_19Dec2019/PREP/mcip/output set InMetFiles = ( /student/home/wsj123/1/CMAQ/wrfout/wrfout_d01_2023-04-09_00:00:00.nc /student/home/wsj123/1/CMAQ/wrfout/wrfout_d02_2023-04-09_00:00:00.nc /student/home/wsj123/1/CMAQ/wrfout/wrfout_d03_2023-04-09_00:00:00.nc ) set LPV = 1 set LWOUT = 0 set LUVBOUT = 1 set IfTer = T set MCIP_START = 2023-04-09-00:00:00.0000 set MCIP_END = 2023-04-14-21:00:00.0000 set INTVL = 60 set IOFORM = 1 set BTRIM = 0 set X0 = 13 set Y0 = 94 set NCOLS = 89 set NROWS = 104 set LPRT_COL = 0 set LPRT_ROW = 0 set WRF_LC_REF_LAT = 40.0 setenv EXECUTION_ID MCIP_RUN_230429 set PROG = mcip date Thu May 29 20:44:36 CST 2025 mkdir -p /student/home/wsj123/1/CMAQ/cmaq5.3.1/CMAQ-CMAQv5.3.1_19Dec2019/PREP/mcip/output if ( 0 != 0 ) then foreach dir ( /student/home/wsj123/1/CMAQ/wrfout /student/home/wsj123/1/CMAQ/cmaq5.3.1/CMAQ-CMAQv5.3.1_19Dec2019/PREP/mcip/src /student/home/wsj123/1/CMAQ/wps_geo ) if ( ! -d /student/home/wsj123/1/CMAQ/wrfout ) then end if ( ! -d /student/home/wsj123/1/CMAQ/cmaq5.3.1/CMAQ-CMAQv5.3.1_19Dec2019/PREP/mcip/src ) then end if ( ! -d /student/home/wsj123/1/CMAQ/wps_geo ) then end if ( T == T ) then if ( ! -f /student/home/wsj123/1/CMAQ/wps_geo/geo_em.d01.nc ) then endif foreach fil ( /student/home/wsj123/1/CMAQ/wrfout/wrfout_d01_2023-04-09_00:00:00.nc /student/home/wsj123/1/CMAQ/wrfout/wrfout_d02_2023-04-09_00:00:00.nc /student/home/wsj123/1/CMAQ/wrfout/wrfout_d03_2023-04-09_00:00:00.nc ) if ( ! -f /student/home/wsj123/1/CMAQ/wrfout/wrfout_d01_2023-04-09_00:00:00.nc ) then end if ( ! -f /student/home/wsj123/1/CMAQ/wrfout/wrfout_d02_2023-04-09_00:00:00.nc ) then end if ( ! -f /student/home/wsj123/1/CMAQ/wrfout/wrfout_d03_2023-04-09_00:00:00.nc ) then end if ( ! -f /student/home/wsj123/1/CMAQ/cmaq5.3.1/CMAQ-CMAQv5.3.1_19Dec2019/PREP/mcip/src/mcip.exe ) then cd /student/home/wsj123/1/CMAQ/cmaq5.3.1/CMAQ-CMAQv5.3.1_19Dec2019/PREP/mcip/output if ( T == T ) then set InGeo = /student/home/wsj123/1/CMAQ/wps_geo/geo_em.d01.nc else set FILE_GD = /student/home/wsj123/1/CMAQ/cmaq5.3.1/CMAQ-CMAQv5.3.1_19Dec2019/PREP/mcip/output/GRIDDESC cat echo Generated namelist: Generated namelist: cat /student/home/wsj123/1/CMAQ/cmaq5.3.1/CMAQ-CMAQv5.3.1_19Dec2019/PREP/mcip/output/namelist.mcip &FILENAMES file_gd = '/student/home/wsj123/1/CMAQ/cmaq5.3.1/CMAQ-CMAQv5.3.1_19Dec2019/PREP/mcip/output/GRIDDESC' file_mm = '/student/home/wsj123/1/CMAQ/wrfout/wrfout_d01_2023-04-09_00:00:00.nc', '/student/home/wsj123/1/CMAQ/wrfout/wrfout_d02_2023-04-09_00:00:00.nc', '/student/home/wsj123/1/CMAQ/wrfout/wrfout_d03_2023-04-09_00:00:00.nc' geo_file = '/student/home/wsj123/1/CMAQ/wps_geo/geo_em.d01.nc' / &CONTROL LPV = 1, LWOUT = 0, LUVBOUT = 1, MCIP_START = '2023-04-09-00:00:00.0000', MCIP_END = '2023-04-14-21:00:00.0000', INTVL = 60, IOFORM = 1, BTRIM = 0, X0 = 13, Y0 = 94, NCOLS = 89, NROWS = 104, LPRT_COL = 0, LPRT_ROW = 0, WRF_LC_REF_LAT = 40.0 / echo echo Running MCIP... Running MCIP... /student/home/wsj123/1/CMAQ/cmaq5.3.1/CMAQ-CMAQv5.3.1_19Dec2019/PREP/mcip/src/mcip.exe This program uses the EPA-AREAL/MCNC-EnvPgms/BAMS Models-3 I/O Applications Programming Interface, [I/O API] which is built on top of the netCDF I/O library (Copyright 1993, 1996 University Corporation for Atmospheric Research/Unidata Program) and the PVM parallel-programming library (from Oak Ridge National Laboratory). Copyright (C) 1992-2002 MCNC, (C) 1992-2018 Carlie J. Coats, Jr., (C) 2003-2012 Baron Advanced Meteorological Systems, LLC, and (C) 2014-2020 UNC Institute for the Environment. Released under the GNU LGPL License, version 2.1. See URL https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for conditions of use. ioapi-3.2: $Id: init3.F90 150 2020-04-11 17:51:44Z coats $ Version with PARMS3.EXT/PARAMETER::MXVARS3= 2048 netCDF version 4.7.0 of Apr 21 2025 17:04:57 $ EXECUTION_ID: MCIP_RUN_230429 ============================================================================== US EPA COMMUNITY MULTISCALE AIR QUALITY MODEL METEOROLOGY-CHEMISTRY INTERFACE PROCESSOR MCIP V5.1 FROZEN 11/21/2019 ============================================================================== ********************************************************************** *** SUBROUTINE: READNML *** ERROR READING NAMELIST FILE ON UNIT 8 *** NAMELIST FILE NAME = namelist.mcip *** NAMELIST = filenames *** IOSTAT = 19 ********************************************************************** *** ERROR ABORT in subroutine READNML ABNORMAL TERMINATION IN READNML if ( 103 != 0 ) then echo MCIP execution failed with status 0 MCIP execution failed with status 0 exit 1
05-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值