code forces 1121C(思维模拟)

博客内容介绍了Vasya关注Codeforces比赛的系统测试过程。文章通过一个具体的例子解释了如何计算在某个时间点显示为'xx%'时正在测试的解决方案,并求解有多少个有趣的提交。文章提到模拟过程复杂,需要读取数据,模拟测试直到所有解决方案完成,并记录机器的测试状态,最终确定有趣解决方案的数量。
摘要由CSDN通过智能技术生成

C. System Testing

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasya likes taking part in Codeforces contests. When a round is over, Vasya follows all submissions in the system testing tab.

There are nn solutions, the ii-th of them should be tested on aiai tests, testing one solution on one test takes 11 second. The solutions are judged in the order from 11 to nn. There are kk testing processes which test solutions simultaneously. Each of them can test at most one solution at a time.

At any time moment tt when some testing process is not judging any solution, it takes the first solution from the queue and tests it on each test in increasing order of the test ids. Let this solution have id ii, then it is being tested on the first test from time moment tt till time moment t+1t+1, then on the second test till time moment t+2

以下是用C语言编写的简单模拟分子热运动的代码: ``` #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #define NUM_PARTICLES 1000 // 粒子数量 #define BOX_SIZE 10.0 // 盒子大小 #define TIME_STEPS 1000 // 时间步长 double rand_range(double min, double max) { return ((double)rand() / RAND_MAX) * (max - min) + min; } double distance(double x1, double y1, double z1, double x2, double y2, double z2) { double dx = x2 - x1; double dy = y2 - y1; double dz = z2 - z1; return sqrt(dx*dx + dy*dy + dz*dz); } int main() { srand(time(NULL)); // 设置随机数种子 double positions[NUM_PARTICLES][3]; // 粒子位置 double velocities[NUM_PARTICLES][3]; // 粒子速度 double forces[NUM_PARTICLES][3]; // 粒子受力 double masses[NUM_PARTICLES]; // 粒子质量 double temperature = 300.0; // 温度 double dt = 0.001; // 时间步长 double kb = 1.38064852e-23; // 玻尔兹曼常数 // 初始化粒子 for (int i = 0; i < NUM_PARTICLES; i++) { positions[i][0] = rand_range(0.0, BOX_SIZE); positions[i][1] = rand_range(0.0, BOX_SIZE); positions[i][2] = rand_range(0.0, BOX_SIZE); velocities[i][0] = rand_range(-1.0, 1.0); velocities[i][1] = rand_range(-1.0, 1.0); velocities[i][2] = rand_range(-1.0, 1.0); masses[i] = rand_range(1.0, 10.0); } // 模拟运动 for (int t = 0; t < TIME_STEPS; t++) { // 计算受力 for (int i = 0; i < NUM_PARTICLES; i++) { forces[i][0] = 0.0; forces[i][1] = 0.0; forces[i][2] = 0.0; for (int j = 0; j < NUM_PARTICLES; j++) { if (i != j) { double d = distance(positions[i][0], positions[i][1], positions[i][2], positions[j][0], positions[j][1], positions[j][2]); double f = (masses[i] * masses[j]) / (d*d); forces[i][0] += f * (positions[j][0] - positions[i][0]) / d; forces[i][1] += f * (positions[j][1] - positions[i][1]) / d; forces[i][2] += f * (positions[j][2] - positions[i][2]) / d; } } } // 更新位置和速度 for (int i = 0; i < NUM_PARTICLES; i++) { velocities[i][0] += forces[i][0] * dt / masses[i]; velocities[i][1] += forces[i][1] * dt / masses[i]; velocities[i][2] += forces[i][2] * dt / masses[i]; positions[i][0] += velocities[i][0] * dt; positions[i][1] += velocities[i][1] * dt; positions[i][2] += velocities[i][2] * dt; } // 控制温度 double kinetic_energy = 0.0; for (int i = 0; i < NUM_PARTICLES; i++) { kinetic_energy += 0.5 * masses[i] * (velocities[i][0]*velocities[i][0] + velocities[i][1]*velocities[i][1] + velocities[i][2]*velocities[i][2]); } double current_temperature = (2.0 / 3.0) * kinetic_energy / (kb * NUM_PARTICLES); double temperature_scale = sqrt(temperature / current_temperature); for (int i = 0; i < NUM_PARTICLES; i++) { velocities[i][0] *= temperature_scale; velocities[i][1] *= temperature_scale; velocities[i][2] *= temperature_scale; } // 输出粒子位置 for (int i = 0; i < NUM_PARTICLES; i++) { printf("%f,%f,%f\n", positions[i][0], positions[i][1], positions[i][2]); } } return 0; } ``` 该代码使用随机数生成粒子的位置、速度和质量,并通过计算受力和更新位置和速度来模拟粒子的运动。此外,该代码还通过控制温度来使粒子保持一定的热运动状态。最后,该代码输出粒子的位置信息,可以用于可视化粒子的运动轨迹。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值