A. Appleman and Toastman(codeforces#263div1)

本文深入探讨了游戏开发中涉及的AI音视频处理技术,包括视频分割、语义识别、自动驾驶等,以及如何应用这些技术来提升游戏体验。
A. Appleman and Toastman
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks:

  • Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman.
  • Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.

After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?

Input

The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman.

Output

Print a single integer — the largest possible score.

Sample test(s)
Input
3
3 1 5
Output
26
Input
1
10
Output
10
Note

Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.

第一次做codeforces的题,不太习惯啊

#include<iostream>
#include<string>
#include<cstring>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
typedef long long ll;
using namespace std;
vector<ll> nums;
int main()
{
  ll n,temp,sum=0;
    cin>>n;
   ll t=n;
   while(t>0)
   {
       t--;
       cin>>temp;
       nums.push_back(temp);
   }
   sum=0;
   sort(nums.begin(),nums.end());
   for(int i=0;i<n-1;i++)
    sum+=(i+2)*nums[i];
   sum+=n*nums[n-1];
   cout<<sum;
   return 0;
}

 

module constants implicit none ! 物理常数 real, parameter :: pi = 3.141592653589793 real, parameter :: R_univ = 8.314462618 ! 通用气体常数 [J/(mol·K)] real, parameter :: R_air = 287.0 ! 空气气体常数 [J/(kg·K)] real, parameter :: k_B = 1.380649e-23 ! 玻尔兹曼常数 [J/K] real, parameter :: N_A = 6.02214076e23 ! 阿伏伽德罗常数 [1/mol] ! 水物性参数 real, parameter :: M_H2O = 0.018015 ! 水的摩尔质量 [kg/mol] real, parameter :: rho_l = 1000.0 ! 液态水密度 [kg/m³] real, parameter :: sigma_H2O = 0.072 ! 表面张力 [N/m] real, parameter :: h_fg = 2.257e6 ! 汽化潜热 [J/kg] real, parameter :: cp_v = 1410.0 ! 水蒸气比热 [J/(kg·K)] real, parameter :: k_v = 0.026 ! 水蒸气导热系数 [W/(m·K)] ! 发动机参数 real, parameter :: De = 0.2 ! 喷口直径 [m] real, parameter :: T0 = 1000.0 ! 喷口温度 [K] real, parameter :: P0 = 50000.0 ! 喷口压力 [Pa] real, parameter :: U0 = 2000.0 ! 喷口速度 [m/s] real, parameter :: X_H2O = 0.22 ! 水蒸气摩尔分数 ! 数值参数 integer, parameter :: nx = 50 ! 轴向网格数 integer, parameter :: ny = 30 ! 径向网格数 integer, parameter :: nt = 1000 ! 时间步数 real, parameter :: dt = 1e-6 ! 时间步长 [s] real, parameter :: L_domain = 5.0 * De ! 轴向计算域长度 [m] real, parameter :: R_domain = 2.0 * De ! 径向计算域半径 [m] ! 组分参数 real, parameter :: X_CO2 = 0.16, X_CO = 0.15, X_N2 = 0.35, X_O2 = 0.12 end module constants program condensation_2d use constants implicit none ! 场变量定义 (二维数组) real :: x(nx, ny), y(nx, ny), dx, dy real :: T_g(nx, ny), P_g(nx, ny), Ux(nx, ny), Uy(nx, ny), rho_g(nx, ny) real :: N_d(nx, ny), Y_d(nx, ny), r_d(nx, ny) ! 液滴数密度、质量分数、半径 real :: m_v(nx, ny), J_nuc(nx, ny), dr_dt(nx, ny) ! 凝结速率、成核率、半径增长率 real :: S(nx, ny), r_c(nx, ny), P_sat(nx, ny) ! 过饱和比、临界半径、饱和蒸气压 ! 辅助变量 real :: mu(nx, ny), lambda(nx, ny), rho_old(nx, ny) integer :: i, j, t_step ! 初始化网格 (轴对称坐标) dx = L_domain / (nx - 1) dy = R_domain / (ny - 1) do j = 1, ny do i = 1, nx x(i, j) = (i - 1) * dx y(i, j) = (j - 1) * dy end do end do ! 初始化流场 (喷口边界条件) call initialize_fields(T_g, P_g, Ux, Uy, rho_g, N_d, Y_d, r_d) ! 时间迭代循环 do t_step = 1, nt ! 保存密度场用于质量守恒 rho_old = rho_g ! 计算物性参数 call calculate_properties(T_g, P_g, mu, lambda) ! 计算过饱和比和临界半径 call calculate_saturation_ratio(P_g, T_g, S, P_sat, r_c) ! 应用Schmidt-Appleman冷凝判据 call apply_condensation_criteria(T_g, rho_g, r_d, S, r_c, J_nuc, dr_dt, m_v) ! 更新液相控制方程 call update_liquid_phase(N_d, Y_d, r_d, J_nuc, m_v, dr_dt, Ux, Uy, dx, dy) ! 更新气相控制方程 (有限差分法) call update_gas_phase(T_g, P_g, Ux, Uy, rho_g, rho_old, mu, lambda, m_v, dx, dy) ! 输出数据 (100步输出一次) if (mod(t_step, 100) == 0) then call output_data(t_step, x, y, T_g, P_g, N_d, Y_d, r_d) end if end do ! 输出最终结果 call output_data(nt, x, y, T_g, P_g, N_d, Y_d, r_d) contains ! 初始化流场 subroutine initialize_fields(T, P, Ux, Uy, rho, N, Y, r) real, intent(out) :: T(:, :), P(:, :), Ux(:, :), Uy(:, :), rho(:, :) real, intent(out) :: N(:, :), Y(:, :), r(:, :) integer :: i, j, nx, ny nx = size(T, 1) ny = size(T, 2) ! 初始化为环境条件 T = 223.15 P = 26500.0 Ux = 0.0 Uy = 0.0 rho = P / (R_air * T) N = 0.0 Y = 0.0 r = 0.0 ! 设置喷口边界条件 (i=1为喷口) do j = 1, ny if (y(1, j) <= De/2.0) then T(1, j) = T0 P(1, j) = P0 Ux(1, j) = U0 Uy(1, j) = 0.0 rho(1, j) = P0 / (R_air * T0) end if end do end subroutine ! 计算物性参数 subroutine calculate_properties(T, P, mu, lambda) real, intent(in) :: T(:, :), P(:, :) real, intent(out) :: mu(:, :), lambda(:, :) integer :: i, j, nx, ny nx = size(T, 1) ny = size(T, 2) ! 简化计算: 动力粘度 (Sutherland公式近似) do j = 1, ny do i = 1, nx mu(i, j) = 1.716e-5 * (T(i, j)/273.0)**0.7 lambda(i, j) = 0.0241 * (T(i, j)/273.0)**0.7 end do end do end subroutine ! 计算饱和比和临界半径 subroutine calculate_saturation_ratio(P, T, S, P_sat, r_c) real, intent(in) :: P(:, :), T(:, :) real, intent(out) :: S(:, :), P_sat(:, :), r_c(:, :) integer :: i, j, nx, ny nx = size(P, 1) ny = size(P, 2) do j = 1, ny do i = 1, nx ! Wagner方程计算饱和蒸气压 (更精确) if (T(i, j) > 273.15) then P_sat(i, j) = 611.0 * exp( -6094.4642/T(i,j) + 21.1249952 - 2.7245552e-2*T(i,j) & + 1.6853396e-5*T(i,j)**2 + 2.4575506*log(T(i,j)) ) else P_sat(i, j) = 611.0 * exp( -6022.7262/T(i,j) + 29.32707 + 1.0613868e-2*T(i,j) & - 1.3198825e-5*T(i,j)**2 - 0.49382577*log(T(i,j)) ) end if ! 过饱和比 S(i, j) = (X_H2O * P(i, j)) / P_sat(i, j) ! Kelvin-Helmholtz临界半径 if (S(i, j) > 1.0) then r_c(i, j) = 2.0 * sigma_H2O / (rho_l * (R_univ/M_H2O) * T(i, j) * log(S(i, j))) else r_c(i, j) = 1e-9 ! 极小值 end if end do end do end subroutine ! 应用冷凝判据并计算相关参数 subroutine apply_condensation_criteria(T, rho_g, r, S, r_c, J_nuc, dr_dt, m_v) real, intent(in) :: T(:, :), rho_g(:, :), r(:, :), S(:, :), r_c(:, :) real, intent(out) :: J_nuc(:, :), dr_dt(:, :), m_v(:, :) integer :: i, j, nx, ny nx = size(T, 1) ny = size(T, 2) ! 成核率 call nucleation_model(T, rho_g, S, r_c, J_nuc) ! 液滴生长率 call droplet_growth_model(T, rho_g, r, r_c, S, dr_dt) ! 凝结质量速率 do j = 1, ny do i = 1, nx if (S(i, j) > 1.0 .and. r(i, j) > 0.0) then m_v(i, j) = J_nuc(i, j) * (4.0 * pi * r_c(i, j)**3 * rho_l / 3.0) & + N_d(i, j) * rho_l * 4.0 * pi * r(i, j)**2 * dr_dt(i, j) else m_v(i, j) = 0.0 end if end do end do end subroutine ! 成核模型 (经典成核理论) subroutine nucleation_model(T, rho_g, S, r_c, J_nuc) real, intent(in) :: T(:, :), rho_g(:, :), S(:, :), r_c(:, :) real, intent(out) :: J_nuc(:, :) real :: A, B, DeltaG integer :: i, j, nx, ny nx = size(T, 1) ny = size(T, 2) do j = 1, ny do i = 1, nx if (S(i, j) > 1.0) then ! 吉布斯自由能变化 DeltaG = 4.0 * pi * r_c(i, j)**2 * sigma_H2O / 3.0 ! 成核率计算 (经典理论) A = rho_g(i, j)**2 / rho_l * sqrt(2.0 * sigma_H2O / (pi * M_H2O**3)) B = 4.0 * pi * r_c(i, j)**2 * sigma_H2O / (3.0 * k_B * T(i, j)) J_nuc(i, j) = A * exp(-B) else J_nuc(i, j) = 0.0 end if end do end do end subroutine ! Gyarmathy液滴生长模型 subroutine droplet_growth_model(T, rho_g, r, r_c, S, dr_dt) real, intent(in) :: T(:, :), rho_g(:, :), r(:, :), r_c(:, :), S(:, :) real, intent(out) :: dr_dt(:, :) real :: lambda_v, Kn, Pr_v, T_sat integer :: i, j, nx, ny nx = size(T, 1) ny = size(T, 2) do j = 1, ny do i = 1, nx if (S(i, j) > 1.0 .and. r(i, j) > 0.0) then ! 克努森数 Kn = sqrt(pi * M_H2O / (2.0 * R_univ * T(i, j))) / r(i, j) ! 普朗特数 (假设) Pr_v = 0.9 ! Gyarmathy模型 (公式28) dr_dt(i, j) = lambda_v * (T_sat(T(i, j), P_g(i, j)) - T(i, j)) * (1.0 - r_c(i, j)/r(i, j)) & / (rho_l * h_fg * r(i, j) * (1.0 + 3.78*(1.0 - 0.82*Kn)/Pr_v * Kn)) else dr_dt(i, j) = 0.0 end if end do end do end subroutine ! 辅助函数: 计算饱和温度 real function T_sat(T, P) real, intent(in) :: T, P ! 简化计算: 使用Clausius-Clapeyron方程 T_sat = 373.15 - (101325.0 - P) * 0.00025 end function ! 更新液相控制方程 (二维轴对称) subroutine update_liquid_phase(N, Y, r, J_nuc, m_v, dr_dt, Ux, Uy, dx, dy) real, intent(inout) :: N(:, :), Y(:, :), r(:, :) real, intent(in) :: J_nuc(:, :), m_v(:, :), dr_dt(:, :) real, intent(in) :: Ux(:, :), Uy(:, :) real, intent(in) :: dx, dy real :: dNdx, dNdy, dYdx, dYdy, conv_N, conv_Y integer :: i, j, nx, ny nx = size(N, 1) ny = size(N, 2) ! 更新液滴数密度和质量分数 do j = 2, ny-1 do i = 2, nx-1 ! 对流项 (一阶迎风) dNdx = (N(i, j) - N(i-1, j)) / dx dNdy = (N(i, j) - N(i, j-1)) / dy conv_N = Ux(i, j) * dNdx + Uy(i, j) * dNdy dYdx = (Y(i, j) - Y(i-1, j)) / dx dYdy = (Y(i, j) - Y(i, j-1)) / dy conv_Y = Ux(i, j) * dYdx + Uy(i, j) * dYdy ! 更新方程 N(i, j) = N(i, j) + dt * (J_nuc(i, j) - conv_N) Y(i, j) = Y(i, j) + dt * (m_v(i, j)/rho_l - conv_Y) ! 更新液滴半径 (考虑生长) if (N(i, j) > 0.0) then r(i, j) = r(i, j) + dt * dr_dt(i, j) ! 从质量和数量计算半径 (作为验证) r(i, j) = max(1e-9, (3.0 * Y(i, j) / (4.0 * pi * rho_l * N(i, j)))**(1.0/3.0) else r(i, j) = 0.0 end if end do end do end subroutine ! 更新气相控制方程 (有限差分法) subroutine update_gas_phase(T, P, Ux, Uy, rho, rho_old, mu, lambda, m_v, dx, dy) real, intent(inout) :: T(:, :), P(:, :), Ux(:, :), Uy(:, :), rho(:, :) real, intent(in) :: rho_old(:, :), mu(:, :), lambda(:, :), m_v(:, :) real, intent(in) :: dx, dy real :: divU, dudx, dudy, dvdx, dvdy, dTdx, dTdy, dPdx, dPdy real :: tau_xx, tau_yy, tau_xy, d2udx2, d2udy2, d2vdx2, d2vdy2 real :: conv_rho, conv_u, conv_v, conv_energy integer :: i, j, nx, ny nx = size(T, 1) ny = size(T, 2) do j = 2, ny-1 do i = 2, nx-1 ! === 连续方程 === divU = (Ux(i+1, j) - Ux(i-1, j))/(2*dx) + (Uy(i, j+1) - Uy(i, j-1))/(2*dy) conv_rho = Ux(i, j)*(rho(i+1,j)-rho(i-1,j))/(2*dx) + Uy(i, j)*(rho(i,j+1)-rho(i,j-1))/(2*dy) rho(i, j) = rho_old(i, j) - dt * (rho(i, j)*divU + conv_rho) - dt * m_v(i, j) ! === 动量方程 (x方向) === ! 对流项 dudx = (Ux(i+1,j) - Ux(i-1,j))/(2*dx) dudy = (Ux(i,j+1) - Ux(i,j-1))/(2*dy) conv_u = Ux(i,j)*dudx + Uy(i,j)*dudy ! 压力梯度 dPdx = (P(i+1,j) - P(i-1,j))/(2*dx) ! 粘性应力 d2udx2 = (Ux(i+1,j) - 2*Ux(i,j) + Ux(i-1,j))/dx**2 d2udy2 = (Ux(i,j+1) - 2*Ux(i,j) + Ux(i,j-1))/dy**2 tau_xx = mu(i,j) * (4.0/3.0*dudx - 2.0/3.0*dudy) ! 动量方程更新 Ux(i,j) = Ux(i,j) + dt * (-conv_u - dPdx/rho(i,j) + (tau_xx + mu(i,j)*(d2udx2 + d2udy2))/rho(i,j)) ! === 动量方程 (y方向) === ! 对流项 dvdx = (Uy(i+1,j) - Uy(i-1,j))/(2*dx) dvdy = (Uy(i,j+1) - Uy(i,j-1))/(2*dy) conv_v = Ux(i,j)*dvdx + Uy(i,j)*dvdy ! 压力梯度 dPdy = (P(i,j+1) - P(i,j-1))/(2*dy) ! 粘性应力 d2vdx2 = (Uy(i+1,j) - 2*Uy(i,j) + Uy(i-1,j))/dx**2 d2vdy2 = (Uy(i,j+1) - 2*Uy(i,j) + Uy(i,j-1))/dy**2 tau_yy = mu(i,j) * (4.0/3.0*dvdy - 2.0/3.0*dvdx) ! 动量方程更新 Uy(i,j) = Uy(i,j) + dt * (-conv_v - dPdy/rho(i,j) + (tau_yy + mu(i,j)*(d2vdx2 + d2vdy2))/rho(i,j)) ! === 能量方程 === ! 对流项 dTdx = (T(i+1,j) - T(i-1,j))/(2*dx) dTdy = (T(i,j+1) - T(i,j-1))/(2*dy) conv_energy = Ux(i,j)*dTdx + Uy(i,j)*dTdy ! 热传导 d2Tdx2 = (T(i+1,j) - 2*T(i,j) + T(i-1,j))/dx**2 d2Tdy2 = (T(i,j+1) - 2*T(i,j) + T(i,j-1))/dy**2 heat_cond = lambda(i,j) * (d2Tdx2 + d2Tdy2) ! 粘性耗散 dissipation = mu(i,j) * (2.0*((dudx)**2 + (dvdy)**2) + (dudy + dvdx)**2) ! 能量方程更新 T(i,j) = T(i,j) + dt * ( -conv_energy + (heat_cond + dissipation)/(rho(i,j)*cp_v) & + m_v(i,j)*h_fg/(rho(i,j)*cp_v) ) ! 状态方程 P(i,j) = rho(i,j) * R_air * T(i,j) end do end do ! 应用边界条件 call apply_boundary_conditions(T, P, Ux, Uy, rho) end subroutine ! 应用边界条件 subroutine apply_boundary_conditions(T, P, Ux, Uy, rho) real, intent(inout) :: T(:, :), P(:, :), Ux(:, :), Uy(:, :), rho(:, :) integer :: i, j, nx, ny nx = size(T, 1) ny = size(T, 2) ! 喷口边界 (i=1) do j = 1, ny if (y(1, j) <= De/2.0) then T(1, j) = T0 P(1, j) = P0 Ux(1, j) = U0 Uy(1, j) = 0.0 rho(1, j) = P0 / (R_air * T0) else ! 无滑移壁面 Ux(1, j) = 0.0 Uy(1, j) = 0.0 ! 绝热壁面 T(1, j) = T(2, j) end if end do ! 出口边界 (i=nx) - 零梯度 do j = 1, ny T(nx, j) = T(nx-1, j) P(nx, j) = P(nx-1, j) Ux(nx, j) = Ux(nx-1, j) Uy(nx, j) = Uy(nx-1, j) rho(nx, j) = rho(nx-1, j) end do ! 对称轴 (j=1) do i = 1, nx Uy(i, 1) = 0.0 ! 对称条件 Ux(i, 1) = Ux(i, 2) T(i, 1) = T(i, 2) P(i, 1) = P(i, 2) rho(i, 1) = rho(i, 2) end do ! 外边界 (j=ny) - 环境条件 do i = 1, nx P(i, ny) = 101325.0 T(i, ny) = 300.0 rho(i, ny) = P(i, ny) / (R_air * T(i, ny)) Ux(i, ny) = 0.0 Uy(i, ny) = 0.0 end do end subroutine ! 数据输出 (二维场) subroutine output_data(step, x, y, T, P, N, Y, r) integer, intent(in) :: step real, intent(in) :: x(:, :), y(:, :), T(:, :), P(:, :), N(:, :), Y(:, :), r(:, :) character(len=50) :: filename integer :: i, j, nx, ny nx = size(T, 1) ny = size(T, 2) ! 云图数据 write(filename, &#39;(a,i6.6,a)&#39;) &#39;field_data_&#39;, step, &#39;.dat&#39; open(unit=10, file=filename, status=&#39;replace&#39;) write(10, *) &#39;Variables = "x", "y", "T", "P", "N", "Y", "r"&#39; write(10, *) &#39;Zone I=&#39;, nx, &#39;, J=&#39;, ny, &#39;, F=Point&#39; do j = 1, ny do i = 1, nx write(10, &#39;(7e16.7)&#39;) x(i, j), y(i, j), T(i, j), P(i, j), N(i, j), Y(i, j), r(i, j) end do end do close(10) ! 中心线数据 if (mod(step, 100) == 0 then open(unit=11, file=&#39;centerline_data.dat&#39;, access=&#39;append&#39;) do i = 1, nx write(11, &#39;(7e16.7)&#39;) step*dt, x(i, 1), T(i, 1), P(i, 1), N(i, 1), Y(i, 1), r(i, 1) end do close(11) end if end subroutine end program condensation_2d根据程序报错修改程序error #6406: Conflicting attributes or multiple declaration of name. [Y] Compilation Aborted (code 1) Compilation Aborted (code 1) error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: :: ) , : error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: :: ) , : error #5082: Syntax error, found IDENTIFIER &#39;THEN&#39; when expecting one of: :: ) , : * <END-OF-STATEMENT> ; . (/ + - ] /) &#39; ** > PRIVATE / // ... error #5082: Syntax error, found IDENTIFIER &#39;THEN&#39; when expecting one of: :: ) , : * <END-OF-STATEMENT> ; . (/ + - ] /) &#39; ** > PRIVATE / // ... error #6317: An ENDIF occurred without a corresponding IF THEN or ELSE statement. error #6317: An ENDIF occurred without a corresponding IF THEN or ELSE statement. error #6404: This name does not have a type, and must have an explicit type. [D2TDX2] error #6404: This name does not have a type, and must have an explicit type. [D2TDX2] error #6404: This name does not have a type, and must have an explicit type. [D2TDY2] error #6404: This name does not have a type, and must have an explicit type. [D2TDY2] error #6404: This name does not have a type, and must have an explicit type. [DISSIPATION] error #6404: This name does not have a type, and must have an explicit type. [DISSIPATION] error #6404: This name does not have a type, and must have an explicit type. [HEAT_COND] error #6404: This name does not have a type, and must have an explicit type. [HEAT_COND] error #6406: Conflicting attributes or multiple declaration of name. [Y] error #6649: This symbol has multiple INTENT statement/attribute declarations which is not allowed. [Y] error #6649: This symbol has multiple INTENT statement/attribute declarations which is not allowed. [Y]
最新发布
06-03
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值