#include <iostream>
#include <string>
using namespace std;
int main()
{
int cases;
while(cin>>cases)
{
for(int rounds=1;rounds<=cases;rounds++)
{
cout<<"Case "<<rounds<<":"<<endl;
int index[36];
for(int i=0;i<36;i++)
cin>>index[i];
int num;
cin>>num;
while(num--)
{
int n,min_cost=1000000000,min_base=100;
cin>>n;
cout<<"Cheapest base(s) for number "<<n<<":";
for(int i=2;i<=36;i++)
{
int cost=0,number=n;
while(number>0)
{
cost+=index[number%i];
number/=i;
}
if(cost<min_cost) min_cost=cost,min_base=i;
}
for(int i=2;i<=36;i++)
{
int cost=0,number=n;
while(number>0)
{
cost+=index[number%i];
number/=i;
}
if(cost==min_cost) cout<<" "<<i;
}
cout<<endl;
}
if(rounds!=cases) cout<<endl;
}
}
return 0;
}
2020年8月6日 星期四
11005 - Cheapest Base
程式碼:
2020年8月5日 星期三
【Hamilton】Farmer Refuted 歌詞筆記
Refuted:駁斥
hear ye:官方發言前的開場詞,尤其在法庭上
heed:注意(警告或建議)
rabble:烏合之眾、暴民
at heart:在心裡
bloodshed:殺戮
astray:誤入歧途
unravel:破壞、拆散
have-nots:富人與窮人
straight face:故意板起的臉孔
thee:你
mange:癬
divisive:引起分歧的
indecisive:優柔寡斷的
niceties:美好、精美
hear ye:官方發言前的開場詞,尤其在法庭上
heed:注意(警告或建議)
rabble:烏合之眾、暴民
at heart:在心裡
bloodshed:殺戮
astray:誤入歧途
unravel:破壞、拆散
have-nots:富人與窮人
straight face:故意板起的臉孔
thee:你
mange:癬
divisive:引起分歧的
indecisive:優柔寡斷的
niceties:美好、精美
11063 - B2-Sequence
程式碼:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n,arr[101],times=1;
while(cin>>n)
{
int flag=1;
for(int i=0;i<n;i++)
cin>>arr[i];
for(int i=0;i<n-1;i++)
{
if(arr[i]>0&&arr[i]<arr[i+1]);
else flag=0;
}
vector<int> sq;
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
if(find(sq.begin(),sq.end(),arr[i]+arr[j])!=sq.end())
flag=0;
else
sq.push_back(arr[i]+arr[j]);
}
}
cout<<"Case #"<<times++<<": ";
if(flag==0) cout<<"It is not a B2-Sequence."<<endl;
else cout<<"It is a B2-Sequence."<<endl;
cout<<endl;
}
return 0;
}
10057 - A mid-summer night's dream.
解題心得:
好像是高中數學?
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n,arr[1000001];
while(cin>>n)
{
int A,two=0,three=0;
for(int i=0;i<n;i++)
cin>>arr[i];
sort(arr,arr+n);
if(n%2) // odd
{
A=arr[n/2];
for(int i=0;i<n;i++)
{
if(arr[i]==A) two++;
}
three=1;
}
else // even
{
A=arr[n/2-1];
for(int i=0;i<n;i++)
{
if(arr[i]==arr[n/2]||arr[i]==arr[n/2-1])
two++;
}
three=arr[n/2]-arr[n/2-1]+1;
}
cout<<A<<" "<<two<<" "<<three<<endl;
}
return 0;
}
2020年8月4日 星期二
948 - Fibonaccimal Base
程式碼:
#include <iostream>
using namespace std;
int main()
{
int f[40],n,num;
f[0]=f[1]=1;
for(int i=2;i<40;i++)
f[i]=f[i-1]+f[i-2];
cin>>n;
while(n--)
{
int start=0;
cin>>num;
cout<<num<<" = ";
for(int i=39;i>=1;i--)
{
if(num/f[i]) cout<<"1",start=1;
else if(start) cout<<"0";
num%=f[i];
}
cout<<" (fib)"<<endl;
}
return 0;
}
10189 - Minesweeper
解題心得:
注意最後一筆測資後不需換行。
程式碼:
注意最後一筆測資後不需換行。
程式碼:
[解一]
#include <iostream>
using namespace std;
int main()
{
int n,m,times=1;
while(cin>>n>>m)
{
if(n==0&&m==0) break;
if(times!=1) cout<<endl;
char map[105][105];
for(int i=0;i<100;i++)
for(int j=0;j<100;j++)
map[i][j]='0';
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>map[i][j];
cout<<"Field #"<<times++<<":"<<endl;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(map[i][j]=='*') cout<<map[i][j];
else
{
int count=0;
for(int x=i-1;x<=i+1;x++)
{
for(int y=j-1;y<=j+1;y++)
{
if(map[x][y]=='*') count++;
}
}
cout<<count;
}
}
cout<<endl;
}
}
return 0;
}
[解二]
#include <iostream>
using namespace std;
int main()
{
int n, m, counter = 1;
int dx[8] = { -1,-1,-1,0,0,1,1,1 }, dy[8] = { -1,0,1,-1,1,-1,0,1 };
while (cin >> n >> m && n && m)
{
if (counter != 1) cout << endl;
char arr[101][101];
for (int i = 0; i < 101; i++)
for (int j = 0; j < 101; j++)
arr[i][j] = '0';
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> arr[i][j];
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (arr[i][j] != '*')
{
int total = 0;
for (int k = 0; k < 8; k++)
{
if (arr[i + dx[k]][j + dy[k]] == '*')
total++;
}
arr[i][j] = total + '0';
}
}
}
cout << "Field #" << counter++ << ":" << endl;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
cout << arr[i][j];
cout << endl;
}
}
return 0;
}
2020年8月3日 星期一
【Hamilton】Aaron Burr, Sir 歌詞筆記
I'm at your service:願為您效勞
sort of:有點
out of sorts:心情不佳
bursar:(學校、大學裡的)財務主管
dying wish:遺願
bargained for:預料(常與more than連用)
buy you a drink:請你喝一杯
run their mouths off:太多話
pint:品脫
Sam Adams:啤酒名
redcoats:英國軍人
chicka:語助詞
cop:警察
lock up:鎖好
corsets:束腹
brew:啤酒
prodigy:神童
verse:韻文
Good luck with that:phrase that people say when you're going to try something that they think will be hard or impossible.
imminent:即將來臨
sort of:有點
out of sorts:心情不佳
bursar:(學校、大學裡的)財務主管
dying wish:遺願
bargained for:預料(常與more than連用)
buy you a drink:請你喝一杯
run their mouths off:太多話
pint:品脫
Sam Adams:啤酒名
redcoats:英國軍人
chicka:語助詞
cop:警察
lock up:鎖好
corsets:束腹
brew:啤酒
prodigy:神童
verse:韻文
Good luck with that:phrase that people say when you're going to try something that they think will be hard or impossible.
imminent:即將來臨
d141: Linearity
解題心得:
看兩條線是否相等,就是列等式看一不一樣。
因為有除以零或者兩點相同的可能,所以把兩邊等式交叉相乘,直接看乘積是否相等。
程式碼:
看兩條線是否相等,就是列等式看一不一樣。
因為有除以零或者兩點相同的可能,所以把兩邊等式交叉相乘,直接看乘積是否相等。
程式碼:
#include<iostream>
using namespace std;
typedef struct
{
int x,y;
}Point;
int main()
{
int cases;
char ignore;
cin>>cases;
while(cases--)
{
Point p1,p2,p3;
cin>>p1.x>>ignore>>p1.y>>p2.x>>ignore>>p2.y>>p3.x>>ignore>>p3.y;
double m1,m2;
if((p2.y-p1.y)*(p3.x-p2.x)==(p2.x-p1.x)*(p3.y-p2.y))
cout<<"collinear"<<endl;
else cout<<"not collinear"<<endl;
}
return 0;
}
10268 - 498-bis
解題心得:
記得再寫一次這題。
程式碼:
記得再寫一次這題。
程式碼:
#include<iostream>
using namespace std;
int a[1000000];
int derivative(int x,int max)
{
long long sum=0,exp=1;
int i;
for(i=max-1;i>=0;i--)
{
sum+=a[i]*exp*(max-i);
exp*=x;
}
return sum;
}
int main()
{
int x,n;
while(cin>>x)
{
for(n=0;;n++)
{
cin>>a[n];
if(getchar()=='\n')
break;
}
cout<<derivative(x,n)<<endl;
}
return 0;
}
2020年8月2日 星期日
簡易翻牌遊戲
使用說明:
總共36格,內為A~R x2 隨機排列的表格。
索引從0開始,35結束。
依指示輸入想翻開的卡牌,若該次兩張牌相同,則成功找出;反之則蓋回去。
沒有防呆,不能輸入0~35外的數字、已被翻開的卡牌索引、每次不得輸入兩相同索引。
(也許還有其他錯誤?)
程式碼:
總共36格,內為A~R x2 隨機排列的表格。
索引從0開始,35結束。
依指示輸入想翻開的卡牌,若該次兩張牌相同,則成功找出;反之則蓋回去。
沒有防呆,不能輸入0~35外的數字、已被翻開的卡牌索引、每次不得輸入兩相同索引。
(也許還有其他錯誤?)
程式碼:
#include <iostream>
using namespace std;
int main()
{
srand(time(NULL));
int index[18]={0},counter=0;
char map[6][6]={'*'},alpha[6][6];
for(int i=0;i<6;i++)
for(int j=0;j<6;j++)
map[i][j]='*',alpha[i][j]='*';
for(int i=0;i<6;i++)
{
for(int j=0;j<6;j++)
{
int letter=rand()%18;
while(index[letter]>=2)
letter=rand()%18;
alpha[i][j]=char(letter+'A');
index[letter]++;
}
}
for(int i=0;i<6;i++)
{
for(int j=0;j<6;j++)
cout<<alpha[i][j]<<" ";
cout<<endl;
}
while(counter<36)
{
int cardIndex1,cardIndex2;
cout<<"Please enter card index: ";
cin>>cardIndex1;
for(int i=0;i<6;i++)
{
for(int j=0;j<6;j++)
{
if(cardIndex1/6==i&&cardIndex1%6==j)
cout<<alpha[i][j]<<" ";
else
cout<<map[i][j]<<" ";
}
cout<<endl;
}
cout<<"Please enter card index: ";
cin>>cardIndex2;
for(int i=0;i<6;i++)
{
for(int j=0;j<6;j++)
{
if(cardIndex1/6==i&&cardIndex1%6==j)
cout<<alpha[i][j]<<" ";
else if(cardIndex2/6==i&&cardIndex2%6==j)
cout<<alpha[i][j]<<" ";
else
cout<<map[i][j]<<" ";
}
cout<<endl;
}
if(alpha[cardIndex1/6][cardIndex1%6]==alpha[cardIndex2/6][cardIndex2%6])
{
cout<<"Good Job!"<<endl;
counter+=2;
map[cardIndex1/6][cardIndex1%6]=alpha[cardIndex1/6][cardIndex1%6];
map[cardIndex2/6][cardIndex2%6]=alpha[cardIndex2/6][cardIndex2%6];
}
else cout<<"Try Again!"<<endl;
}
cout<<"Congratulation!!"<<endl;
}
2020年8月1日 星期六
10908 - Largest Square
解題心得:
細節要注意。
程式碼:
細節要注意。
程式碼:
#include <iostream>
using namespace std;
int main()
{
int t,m,n,q,r,c;
cin>>t;
while(t--)
{
char map[100][100]={'0'};
cin>>m>>n>>q;
cout<<m<<" "<<n<<" "<<q<<endl;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cin>>map[i][j];
while(q--)
{
cin>>r>>c;
int length=0,out=0;
char target=map[r][c];
while(1)
{
int i,j;
for(i=r-length;i<=r+length;i++)
{
for(j=c-length;j<=c+length;j++)
{
if(map[i][j]!=target)
{
out=1;
break;
}
else if(i<0||j<0||i>=m||j>=n)
{
out=1;
break;
}
}
if(out) break;
}
if(out)
{
length--;
break;
}
length++;
}
cout<<length*2+1<<endl;
}
}
return 0;
}
訂閱:
文章 (Atom)