> [TOC]
>
> [time=Sun, Dec 3, 2023 8:43 PM]
# a072: uva10849. Move the Bishop **
http://140.113.72.36:207/ShowProblem?problemid=a072
>行列差值為0 =>不用走 ,行列差值相同 => 走1 ,
行列差值奇偶相同 => 走2 ,行列奇偶不同 => no move
```cpp=
//a072: uva10849. Move the Bishop
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int c,t,n,r1,c1,r2,c2;
cin>>c;
while(cin>>t>>n)
{
while(t--)
{
cin>>r1>>c1>>r2>>c2;
if(r1==r2&&c1==c2)//不用走 ***
{
cout<<"0"<<endl;
}
else if(abs(r1-r2)==abs(c1-c2))//行列差相同
{
cout<<"1"<<endl;
}
else if(abs(r1-r2)!=abs(c1-c2))//行列差不同
{
if(abs(r1-r2)%2==abs(c1-c2)%2)//奇偶同
{
cout<<"2"<<endl;
}
else if(abs(r1-r2)%2!=abs(c1-c2)%2)//奇偶不同
{
cout<<"no move"<<endl;
}
}
}
}
return 0;
}
```
# a082: uva.10038 Jolly Jumpers *****
> http://140.113.72.36:207/ShowProblem?problemid=a082
>計算差值 並將<**difference[j]** **(預設是0)**>中的1~n-1格設成1
>預設jolly ,如果在這範圍中有任何差值不存在 => not jolly
```cpp=
//a082: uva.10038 Jolly Jumpers
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
int number[3000];
while(cin>>n)
{
bool jolly =true;//預設jolly ***
for(int i=0;i<n;i++)//輸入array
{
cin>>number[i];
}
int difference[3000]={0};//紀錄差值是否存在 ***
int diff;
for(int j=0;j<n;j++)
{
diff=abs(number[j]-number[j+1]);//計算差值 ***
difference[diff]=1;//紀錄差值存在***
}
for(int k=1;k<n;k++)//檢查差值1~n-1是否都存在*****
{
if(difference[k]==0)//一個差值不存在 => not jolly
{
jolly=false;
break;
}
}
if(jolly==true)
{
cout<<"Jolly"<<endl;
}
else if(jolly==false)
{
cout<<"Not jolly"<<endl;
}
}
return 0;
}
```
# a086: uva.11059 Maximum Product*****
> http://140.113.72.36:207/ShowProblem?problemid=a086
> **用long long int**
> 開始位置i從0到n-1
> 結束位置j從i到n-1
> 每個(i,j)的結果判斷<**product(預設是1)**>是否成為<**maxproduct(預設是0)**>
```cpp=
//a086: uva.11059 Maximum Product
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
int number[18];
int casenumber =1;//現在case數 ***
while(cin>>n)
{
for(int i=0;i<n;i++)//輸入array
{
cin>>number[i];
}
long long int maxproduct=0;//long long 重置*****
for(int i=0;i<n;i++)//從i=0開始 ...=>從i=n-1開始 ***
{
long long int product=1;//long long 重置*****
for(int j=i;j<n;j++)//乘到i ...=>乘到n-1 ***
{
product*=number[j];
maxproduct=max(maxproduct,product);//取max*****
}
}
cout<<"Case #"<<casenumber++<<": The maximum product is "<<maxproduct<<"."<<endl;
cout<<endl;
}
return 0;
}
```
# a088: uva.11204 Musical Instruments*****
> http://140.113.72.36:207/ShowProblem?problemid=a088
> 學生i從0~m, 樂器j從0~n,逐一輸入
遇到1時在相對應的<**array[j]** **(預設都是0)**>上+1
> <**ans(預設是1)**>要乘上**每個樂器重複的人數**
```cpp=
//a088: uva.11204 Musical Instruments
#include <iostream>
using namespace std;
int main()
{
int t,n,m,rank,ans;
cin>>t;
while(cin>>n>>m)
{
int total[32]={0};//要重置成0 *****
ans=1;//重置成1 *****
for(int i=0;i<m;i++)//m位學生
{
for(int j=0;j<n;j++)//n個樂器
{
cin>>rank;//輸入排名
if(rank==1)
{
total[j]++;//紀錄+1
}
}
}
for(int j=0;j<n;j++)//檢查重複紀錄
{
if(total[j]>0)
{
ans*=total[j];
}
}
cout<<ans<<endl;
}
return 0;
}
```
# a093: uva.12650 Dangerous Dive*****
> http://140.113.72.36:207/ShowProblem?problemid=a093
>回來的r個人依照輸入在相對應的<**array[i]** **(預設是0)**>位置上設成1
>檢查j從1~n , array[j]==0時 輸出j值
```cpp=
//a093: uva.12650 Dangerous Dive
#include <iostream>
using namespace std;
int main()
{
int n,r,back;
while(cin>>n>>r)
{
int s[105]={0};//預設是0*****
for(int i=1;i<=r;i++)//輸入回來的
{
cin>>back;
s[back]=1;//存活紀錄為1
}
if(n==r)//全部存活
{
cout<<"*"<<endl;
}
else //n!=r 不要用break*****
{
for(int j=1;j<=n;j++)
{
if(s[j]==0)//輸出沒回來的
{
cout<<j<<" ";
}
}
cout<<endl;
}
}
return 0;
}
```
# a101: Parking***
> http://140.113.72.36:207/ShowProblem?problemid=a101
> 用<**algorithm**>由小到大排序 然後輸出2*(x[n-1]-x[0])
```cpp=
//a101: Parking
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int t,n;
int x[20];
cin>>t;
while(cin>>n)
{
for(int i=0;i<n;i++)
{
cin>>x[i];
}
sort(x,x+n);//小到大排序 ***
cout<<(x[n-1]-x[0])*2<<endl;//最後(n-1)減第一(0)***
}
return 0;
}
```