Problem A B C D E G H are included.
A. Fried Fish
题意:
N 条鱼要煎熟,每次煎鱼锅中只能煎 K 条鱼的一面(一条鱼要煎两面),问最少要煎几次?
思路:
由于一次只能煎鱼身的一面,故最少要煎两次。max(2,ceil(n*2/k))即可
代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
double n,m;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
while(cin>>n>>m){
cout<<max(ceil(n*2.0/m),2.0)<<endl;
}
}
B. Hanoi tower
题意:
本题题意与样例似乎有矛盾,我觉得题目应该是这样的:
问 N 个盘子的汉诺塔,在第几次移动时,三根柱子上的盘子数一样。保证 N%3==0。
当 N == 3的时候,答案是 2。
思路:
先跑一边汉诺塔,打表找规律。发现
A[3] = 2 , A[6] = 9
当 N 是奇数时 A[N] = A[N-3] * 4 + 2
当 N 是偶数时 A[N] = A[N-3] * 4 -TMP[N];TMP[12]=17 TMP[N]=TMP[N-6]*4+21;
代码:
汉诺塔:
#include <iostream>
#include <stdio.h>
using namespace std;
long long ans;
string steps;
int cut[3];
bool flag;
string add(string str1,string str2){
int len1=str1.size();
int len2=str2.size();
if(len1<len2){
swap(str1,str2);
swap(len1,len2);
}
int c=0;
for(int i=len1-1,j=len2-1;i>=0;i--,j--){
int temp=0;
if(j>=0)
temp+=str2[j]-'0';
temp+=str1[i]+c-'0';
str1[i]=temp%10+'0';
c=temp/10;
}
if(c)
str1='1'+str1;
return str1;
}
void judge(){
if(cut[0]==cut[1]&&cut[1]==cut[2]){cout<<steps<<endl;flag=0;}
}
int move(int x,char a,char b)
{
cut[a-'A']--;cut[b-'A']++