问题标题: 酷町堂:3424怎么做????求大神指导!!

0
0
已解决
刘承志
刘承志
中级光能
中级光能

如果一个有天平,砝码重量均为n的次方数:n0,n1,n2,n3,n4,n5,…,每种砝码都有无数个,那么用这个天平可以称出任意正整数的重量。但是称一个物品时,不一定只在物品的另一边放砝码,也可以在物品的一边放置砝码。

例如n=10,称出重量9的物品,只需要在物品一端放上1个1砝码,另一端放上1个10砝码,而不必在另一端放9个1砝码。n=10时称出重量9的物品至少需要2个砝码。

请问对给定的n,要称出重量m,至少需要多少个砝码?

输入描述 Input Description

第一行一个正整数m,表示要称的重量;

第二行一个正整数n,表示砝码重量底数n。

输出描述 Output Description

一个整数,表示最少需要多少个砝码。

样例输入 Sample Input

 

99
10

样例输出 Sample Output

 

2

数据范围及提示 Data Size & Hint

对于30%的数据点,m≤2^63-1

对于100%的数据点,0≤m≤10^10000,1<n≤10000


0
已采纳
汤启恩
汤启恩
新手光能
新手光能

8分题,建议打牢基础再做。如果你能做出来送你个代码:

#include<iostream>
using namespace std;
int main()
{   
    cout<<"孩子,你太优秀了!!!";
    return 0;
}

汤启恩在2019-07-30 19:19:51追加了内容

求采纳

 

0
0
张亦阳
张亦阳
资深守护
资深守护


#include "windows.h"
#include "stdio.h"
#include "IPHlpApi.h"
#include "Nb30.h"
#pragma comment( lib, "iphlpapi.lib" )
#pragma comment( lib, "Netapi32.lib")
#define BUFSIZE 80
#define ALLOCATE_FROM_PROCESS_HEAP( bytes )   HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bytes )
#define DEALLOCATE_FROM_PROCESS_HEAP( ptr )   if( ptr ) HeapFree( GetProcessHeap(), 0, ptr )
typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER    NameBuff[30];
} ASTAT, * PASTAT;
// 得到操作系统版本
void GetOSVersion()
{
OSVERSIONINFOEX osvi;
BOOL bOsVersionInfoEx;
char OsVersion[128];
// Try calling GetVersionEx using the OSVERSIONINFOEX structure.
// If that fails, try using the OSVERSIONINFO structure.
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
{
   osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
   if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) 
   {
    printf("GetSystemVersion failed!\n");
    return;
   }
}
switch (osvi.dwPlatformId)
{
   // Test for the Windows NT product family.
case VER_PLATFORM_WIN32_NT:
   // Test for the specific product family.
   if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
    strcpy(OsVersion,"Microsoft Windows Server2003 family, ");
   if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
    strcpy (OsVersion,"Microsoft Windows XP ");
   if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
    strcpy(OsVersion,"Microsoft Windows 2000 ");
   if ( osvi.dwMajorVersion <= 4 )
    strcpy(OsVersion,"Microsoft Windows NT ");
   // Test for specific product on Windows NT 4.0 SP6 and later.
   if( bOsVersionInfoEx )
   {
    // Test for the workstation type.
    if ( osvi.wProductType == VER_NT_WORKSTATION )
    {
     if( osvi.dwMajorVersion == 4 )
      strcat(OsVersion, "Workstation 4.0 " );
     else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
      strcat( OsVersion,"Home Edition " );
     else
      strcat( OsVersion,"Professional " );
    }
    // Test for the server type.
    else if ( osvi.wProductType == VER_NT_SERVER )
    {
     if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
     {
      if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
       strcat(OsVersion,"Datacenter Edition " );
      else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
       strcat(OsVersion,"Enterprise Edition " );
      else if( osvi.wSuiteMask == VER_SUITE_BLADE )
       strcat(OsVersion,"Web Edition " );
      else
       strcat(OsVersion,"Standard Edition " );
     }
     else if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
     {
      if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
       strcat(OsVersion,"Datacenter Server " );
      else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
       strcat(OsVersion, "Advanced Server " );
      else
       strcat(OsVersion,"Server " );
     }
     else // Windows NT 4.0 
     {
      if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
       strcat(OsVersion,"Server 4.0, Enterprise Edition " );
      else
       strcat(OsVersion,"Server 4.0 " );
     }
    }
   }
   else // Test for specific product on Windows NT 4.0 SP5 and earlier
   {
    HKEY hKey;
    char szProductType[BUFSIZE];
    DWORD dwBufLen=BUFSIZE;
    LONG lRet;
    lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
     "SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
     0, KEY_QUERY_VALUE, &hKey );
    if( lRet != ERROR_SUCCESS )
     return;
    lRet = RegQueryValueEx( hKey, "ProductType", NULL, NULL,
     (LPBYTE) szProductType, &dwBufLen);
    if( (lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE) )
     return;
    RegCloseKey( hKey );
    if ( lstrcmpi("WINNT", szProductType) == 0 )
     strcat(OsVersion, "Workstation " );
    if ( lstrcmpi("LANMANNT", szProductType) == 0 )
     strcat(OsVersion,"Server " );
    if ( lstrcmpi("SERVERNT", szProductType) == 0 )
     strcat(OsVersion,"Advanced Server " );
    printf( "%d.%d ", osvi.dwMajorVersion, osvi.dwMinorVersion );
   }
   // Display service pack (if any) and build number.
   if( osvi.dwMajorVersion == 4 && 
    lstrcmpi( osvi.szCSDVersion, "Service Pack 6" ) == 0 )
   {
    HKEY hKey;
    LONG lRet;
    // Test for SP6 versus SP6a.
    lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
     "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009",
     0, KEY_QUERY_VALUE, &hKey );
    if( lRet == ERROR_SUCCESS )
     printf( "Service Pack 6a (Build %d)\n", osvi.dwBuildNumber & 0xFFFF );         
    else // Windows NT 4.0 prior to SP6a
    {
     printf( "%s (Build %d)\n",
      osvi.szCSDVersion,
      osvi.dwBuildNumber & 0xFFFF);
    }
    RegCloseKey( hKey );
   }
   else // Windows NT 3.51 and earlier or Windows 2000 and later
   {
    //    printf( "%s (Build %d)\n",
    //      osvi.szCSDVersion,
    //      osvi.dwBuildNumber & 0xFFFF);
    char temp[10];
    strcat(OsVersion," ");
    strcat(OsVersion,osvi.szCSDVersion);
    _itoa(osvi.dwBuildNumber & 0xFFFF,temp,10);
    strcat(OsVersion," (Build");
    strcat(OsVersion,temp);
    strcat(OsVersion,")\n");
   }
   break;
   // Test for the Windows 95 product family.
case VER_PLATFORM_WIN32_WINDOWS:
   if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
   {
    strcpy(OsVersion,"Microsoft Windows 95 ");
    if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' )
     strcat(OsVersion," OSR2 " );
   }
   if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
   {
    strcpy(OsVersion,"Microsoft Windows 98 ");
    if ( osvi.szCSDVersion[1] == 'A' )
     strcat(OsVersion," SE " );
   }
   if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
   {
    strcpy(OsVersion,"Microsoft Windows Millennium Edition\n");
   } 
   break;
case VER_PLATFORM_WIN32s:
   strcpy(OsVersion,"Microsoft Win32s\n");
   break;
}
printf("OS: ");
printf(OsVersion);
}
 
//得到运行时间
void GetRunningTime()
{
DWORD dwTime;
int nDay,nHour,nMinute;
dwTime = GetTickCount();
nMinute = dwTime / 60000;
nHour = nMinute / 60;
nMinute = nMinute - nHour * 60;
nDay = nHour / 24;
printf("Running Time: ");
printf("%d day(s),",nDay);
printf("%d hour(s),",nHour);
printf("%d minute(s)",nMinute);
printf("\n");
}
//得到计算机名
void GetMyComputerName()
{
LPTSTR lpszName;
DWORD dwSize = 1024;
TCHAR tchBuffer[1024];
lpszName = tchBuffer;
GetComputerName(lpszName,&dwSize);
printf("Computer Name: ");
printf("%s",lpszName);
printf("\n");
}
//得到当前用户名
void GetCurrentUser()
{
LPTSTR lpszName;
DWORD dwSize = 1024;
TCHAR tchBuffer[1024];
lpszName = tchBuffer;
GetUserName(lpszName,&dwSize);
printf("Current User: ");
printf("%s",lpszName);
printf("\n");
}
//得到系统目录
void GetMySystemDirectory()
{
LPTSTR lpszName;
DWORD dwSize = MAX_PATH + 1;
TCHAR tchBuffer[MAX_PATH];
lpszName = tchBuffer;
GetSystemDirectory(lpszName,dwSize);
printf("System Directory: ");
printf("%s",lpszName);
printf("\n");
}
//得到CPU信息
void GetCPUInfo()
{
long lResult;
HKEY hKey;
TCHAR tchData[64];
DWORD dwSize;
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Hardware\\Description\\System\\CentralProcessor\\0",0,KEY_QUERY_VALUE,&hKey);
if(lResult == ERROR_SUCCESS)
{
   dwSize = sizeof(tchData);
   RegQueryValueEx(hKey,"ProcessorNameString",NULL,NULL,(LPBYTE)tchData,&dwSize);
   printf("CPU: ");
   printf("%s",tchData);
}
else
{
   printf("CPU: ");
   printf("Unknown");
}
RegCloseKey(hKey);
printf("\n");
}
//得到内存信息
void GetMemoryInfo()
{
long lVar;
MEMORYSTATUS memoryStatus;
memset(&memoryStatus, sizeof (MEMORYSTATUS), 0);
memoryStatus.dwLength = sizeof (MEMORYSTATUS);
GlobalMemoryStatus (&memoryStatus);
 
lVar = memoryStatus.dwTotalPhys / 1024;
printf("Total Memory: ");
printf("%ld KB\n",lVar);
 
lVar = memoryStatus.dwAvailPhys / 1024;
printf("Available Memory: ");
printf("%ld KB\n",lVar);
}
//得到磁盘信息
void GetDiskInfo()
{
DWORD lInfoSize = GetLogicalDriveStrings(0, NULL);//总磁盘名大小
char * chDriver;
size_t lDriveSize;
chDriver = malloc(lInfoSize + sizeof(""));
if(GetLogicalDriveStrings(lInfoSize,chDriver) != lInfoSize - 1)
{
   printf("Cannot get disk information.\n");
   return;
}
printf("Disk Information:\n");
lDriveSize = strlen(chDriver);//每个磁盘名大小
while( lDriveSize > 0 )//循环来得到所有分区名,如c:\,d:\...
{
   UINT nType;
   ULARGE_INTEGER nTotalBytes, nTotalFreeBytes, nTotalAvailable;
   printf("%s ",chDriver);
   nType = GetDriveType(chDriver);
   switch(nType)
   {
   case DRIVE_FIXED:
    printf("(FIXED) ");
    break;
   case DRIVE_CDROM:
    printf("(CDROM)\n");
    break;
   case DRIVE_RAMDISK:
    printf("(RAMDISK)\n");
    break;
   case DRIVE_REMOTE:
    printf("(REMOTE)\n");
    break;
   case DRIVE_REMOVABLE:
    printf("(REMOVABLE)\n");
    break;
   case DRIVE_UNKNOWN:
    printf("(UNKNOWN)\n");
    break;
   }
   if(nType == DRIVE_FIXED)
   {
    if(GetDiskFreeSpaceEx(chDriver, &nTotalAvailable, &nTotalBytes, &nTotalFreeBytes))//得到磁盘空间信息
    {
     printf("Total Size: ");
     printf("%ld KB,",nTotalBytes.QuadPart/1024);//总大小
     printf("Free Size: ");
     printf("%ld KB\n",nTotalFreeBytes.QuadPart/1024);//剩余大小
    }
   }
   chDriver += lDriveSize + 1;
   lDriveSize = strlen(chDriver);

}
//得到MAC地址
void GetMacAddress(DWORD dwIndex)
{
ASTAT Adapter;
NCB ncb;
UCHAR uRetCode;
LANA_ENUM lana_enum;
 
memset(&ncb,0,sizeof(ncb));
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (unsigned char *)&lana_enum;
ncb.ncb_length = sizeof(lana_enum);
uRetCode = Netbios(&ncb);
memset(&ncb, 0, sizeof(ncb));
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = lana_enum.lana[dwIndex];
uRetCode = Netbios(&ncb);
memset(&ncb, 0, sizeof(ncb));
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = lana_enum.lana[dwIndex];
strcpy((char *)ncb.ncb_callname, "*   ");
ncb.ncb_buffer = (unsigned char *) &Adapter;
ncb.ncb_length = sizeof(Adapter);
uRetCode = Netbios(&ncb);
printf("MAC Address: %02x:%02x:%02x:%02x:%02x:%02x\n",Adapter.adapt.adapter_address[0],
    Adapter.adapt.adapter_address[1],
    Adapter.adapt.adapter_address[2],
    Adapter.adapt.adapter_address[3],
    Adapter.adapt.adapter_address[4],
    Adapter.adapt.adapter_address[5]);
}
//得到网卡信息
void GetNetAdapterInfo()
{
IP_ADAPTER_INFO * pAdptInfo = NULL;
IP_ADAPTER_INFO * pNextAd = NULL; 
ULONG ulLen      = 0;
DWORD dwCount               = 0;//网卡个数
DWORD dwRet;
dwRet = GetAdaptersInfo( pAdptInfo, &ulLen );
if( dwRet == ERROR_BUFFER_OVERFLOW ) 
{
   pAdptInfo = ( IP_ADAPTER_INFO* )ALLOCATE_FROM_PROCESS_HEAP( ulLen );
   dwRet = GetAdaptersInfo( pAdptInfo, &ulLen );  
}
pNextAd = pAdptInfo;
while( pNextAd ) 
{
   dwCount ++;
   pNextAd = pNextAd->Next;
}
printf("Network Adapter:\n");
if( dwRet == ERROR_SUCCESS ) 
{
   pNextAd = pAdptInfo;
   while( pNextAd ) 
   {
    //网卡描述
    IP_ADDR_STRING * pNext = NULL;
    printf("Description: %s\n",pNextAd->Description);
    //获得MAC地址
    GetMacAddress(-- dwCount);
    //IP地址和子网掩码
    pNext = &( pNextAd->IpAddressList);
    printf("IP Address: %s\n",pNext->IpAddress.String);
    printf("SubNet Mask: %s\n",pNext->IpMask.String);
    //默认网关
    pNext = &( pNextAd->GatewayList );
    printf("Default Gateway: %s\n",pNext->IpAddress.String);
    printf("\n");
    pNextAd = pNextAd->Next;
   }
}
DEALLOCATE_FROM_PROCESS_HEAP( pAdptInfo );
}
main()
{
printf("\r\n");
printf("Detect System Information, by sky-studio");
printf("\r\n");
printf("Written by sky, hacklaolang@qq.com");
printf("\r\n");
printf("\r\n");
GetOSVersion();//得到操作系统版本
GetRunningTime();//得到运行时间
GetMyComputerName();//得到计算机名
GetCurrentUser();//得到当前用户名
GetMySystemDirectory();//得到系统目录
GetCPUInfo();//得到CPU信息
GetMemoryInfo();//得到内存信息
printf("\n");
GetDiskInfo();//得到磁盘信息
printf("\n");
GetNetAdapterInfo();//得到网卡信息

这个程序运行不出来结果,#include "Iphlpapi.h"出现错误,

--------------------- 
作者:勇zhe无wei 
来源:CSDN 
原文:https://blog.csdn.net/zhangxxxww/article/details/8125013 
版权声明:本文为博主原创文章,转载请附上博文链接!

0
0
我要回答