64,282
社区成员
发帖
与我相关
我的任务
分享
#define EXCLUDE 13
#define INTERVAL 1
int F_CAL_DIC(int n,int m,int s)
{
int t=s/(m+INTERVAL);
if (t>=n)
{
if (n%EXCLUDE) return 1;
else return 2;
}
else
{
if (t%EXCLUDE) return 1+F_CAL_DIC(n-t,m,s);
else return 1+F_CAL_DIC(n-t+1,m,s);
}
return -1;
}
int main()
{
int n=0,m=0,s=0;
scanf("%d %d %d",&n,&m,&s);
printf("%d\n",F_CAL_DIC(n,m,s));
return 0;
}
int GetDiskCount(int n, int m, int s)
{
int mTemp = m + 1;
int nCount = (s+1)/mTemp;
if(n > nCount && nCount % 13 == 0)
{
nCount -- ;
}
else if (n <= nCount && n % 13 == 0)//
{
nCount = n;
nCount --;
}
return (n / nCount * nCount == n) ? (n / nCount) : (n / nCount + 1);
}
int GetDiskCount(int n, int m, int s)
{
int mTemp = m + 1;
int nCount = (s+1)/mTemp;
if(nCount==13)
{
nCount --;
}
return (n / nCount * nCount == n) ? (n / nCount) : (n / nCount + 1);
}
#define EXCLUDE 13
#define INTERVAL 1
int F_CAL_DIC(int n,int m,int s)
{
if (m==s) return n; //考虑可能相等
int t=(s+INTERVAL)/(m+INTERVAL); //考虑n 1 99 每盘能存下50的情况
if (t>=n)
{
if (n%EXCLUDE) return 1;
else return 2;
}
else
{
if (t%EXCLUDE) return 1+F_CAL_DIC(n-t,m,s);
else return 1+F_CAL_DIC(n-t+1,m,s);
}
return -1;
}
int main()
{
int n=0,m=0,s=0;
scanf("%d %d %d",&n,&m,&s);
printf("%d\n",F_CAL_DIC(n,m,s));
return 0;
}
int GetMinDiscCount(int n, int m, int s)
{
const int distTime = 1; // 间隔时间 1s
int musicPerDisc = (s+distTime)/(m+distTime); // 每张盘放的歌的数量
if(musicPerDisc % 13 == 0) // 对于13的迷信问题处理
--musicPerDisc;
int discCount = n/musicPerDisc; // 唱片数量
int otherMusic = n - musicPerDisc * discCount; // 当前唱片数量下剩余的music数量,这些已不足一张唱片了
if(otherMusic != 0) // 增加剩余music数量不为0的处理
{
/* 经测试,只有一种情形比较特殊:当剩余数量是13的倍数,且与其他盘数量相差为1或无盘分配时,需要扩充2个盘
* 如用例:53 2 80 */
if(otherMusic % 13 == 0 && (discCount == 0 || musicPerDisc - otherMusic == 1))
discCount += 2;
else
++discCount;
}
return discCount;
}
int GetMinDiscCount(int n, int m, int s)
{
const int distTime = 1; // 间隔时间 1s
int musicPerDisc = (s+distTime)/(m+distTime); // 每张盘放的歌的数量
if(musicPerDisc % 13 == 0) // 对于13的迷信问题处理
--musicPerDisc;
int discCount = n/musicPerDisc; // 唱片数量
int otherMusic = n - musicPerDisc * discCount; // 当前唱片数量下剩余的music数量,这些已不足一张唱片了
if(otherMusic != 0) // 增加剩余music数量不为0的处理
{
if(otherMusic % 13 == 0) // 要注意剩余的唱片数量是否是13的倍数
discCount += 2;
else
++discCount;
}
return discCount;
}
#include <time.h>
int _tmain(int argc, _TCHAR* argv[])
{
printf("%d\t %d\t %d\t -> %d\n", 26, 1, 100, GetMinDiscCount(26, 1, 100));
srand((unsigned int)time(NULL));
for(int i = 0; i < 30; i++)
{
int n = rand()%100 + 1;
int s = rand()%10000 + 1;
int m = rand()%s + 1;
printf("%d\t %d\t %d\t -> %d\n", n, m, s, GetMinDiscCount(n, m, s));
}
system("pause");
return 0;
}