# 求教这个问题用C语言的实现

Problem Description
You are given N baskets of gold coins. The baskets are numbered from 1 to N. In all except one of the baskets, each gold coin weighs w grams. In the one exceptional basket, each gold coin weighs w-d grams. A wizard appears on the scene and takes 1 coin from Basket 1, 2 coins from Basket 2, and so on, up to and including N-1 coins from Basket N-1. He does not take any coins from Basket N. He weighs the selected coins and concludes which of the N baskets contains the lighter coins. Your mission is to emulate the wizard's computation.

Input
The input file will consist of one or more lines; each line will contain data for one instance of the problem. More specifically, each line will contain four positive integers, separated by one blank space. The first three integers are, respectively, the numbers N, w, and d, as described above. The fourth integer is the result of weighing the selected coins.

N will be at least 2 and not more than 8000. The value of w will be at most 30. The value of d will be less than w.

Output
For each instance of the problem, your program will produce one line of output, consisting of one positive integer: the number of the basket that contains lighter coins than the other baskets.

Sample Input
10 25 8 1109
10 25 8 1045
8000 30 12 959879400

Sample Output
2
10
50

• 写回答

#### 2条回答默认 最新

• threenewbee 2018-11-21 12:10
关注
``````#include<stdio.h>
#include<string.h>
#define LL long long
int main()
{
int w,d,n;
int i;
LL m,sum,ans;
while(scanf("%d%d%d%lld",&n,&w,&d,&m)!=EOF)
{
sum=0;
for(i=1;i<n;i++)
sum+=i*w;
ans=sum-m;
if(ans==0)
printf("%d\n",n);
else
printf("%lld\n",ans/d);
}
return 0;
}
``````
本回答被题主选为最佳回答 , 对您是否有帮助呢?
评论

#### 悬赏问题

• ¥15 如何利用闲置机械硬盘变现
• ¥15 信号处理中的凸优化问题
• ¥15 arm虚拟机无法和物理机互通
• ¥15 如何在此代码上增加一个统计学生生源的功能？(语言-c语言)
• ¥15 Android导航条遮盖异常
• ¥15 计算机网络技术基础问题
• ¥15 设置mac系统只能访问指定网站
• ¥15 西门子博途 s7 1200控制三台步进电机
• ¥15 基于非参数的方向距离函数求污染物影子价格(有偿)
• ¥15 vue+element 生成table