Ex1. 雞兔同籠, 雞跟兔的數量都小於一萬
輸入範例
1 // #case
14 7 //腳 頭
輸出範例
7 0 //雞 兔
測資
5
14 7
22 7
9998 4499
556 139
59994 19998
答案
7 0
3 4
3999 500
0 139
9999 9999
|
Ex2. 外星版雞同籠 (題目設計)
輸入範例
2 3 // #spicies #testcase
2 1 // 物種0的 腳 頭
4 1 // 物種1的 腳 頭
14 7 // 第0籠
22 7 // 第1籠
9998 4499 // 第2籠
輸出範例
7 0
3 4
3999 500
Ex3. 堆積木,以長方堆正方, Ex 2x3 的積木可以堆出的最小正方形, #piece
輸入範例
1 // #case
2 3
輸出範例
6
測資
3
2 3
250 375
30641 25927
|
解答
6
6
143
|
Ex4 由分子量推化學式
ax+by+cz=46
x+12y+16z=46, x,y,z >=1
輸入範例
1 //#case
46 3 //分子量 元素
1 12 16 //原子量
輸出範例
3
18 1 1
6 2 1
2 1 2
測資
3
46 3
1 12 16
60 3
1 12 16
106 3
12 16 23
|
解答
3
18 1 1
6 2 1
2 1 2
5
4 2 2
16 1 2
8 3 1
20 2 1
32 1 1
1
1 3 2
|
程式碼
#include<iostream>
#include<vector> using namespace std;int main() { int numofcase; cin>>numofcase; while (numofcase--){ int amount=0; int moleculer; cin>>moleculer; int numofelement; cin>>numofelement; int b,c,e; cin>>e>>c>>b; int bstart=moleculer/b; for(int z=bstart;z>0;z--){ int moleculer2=moleculer; moleculer2=moleculer2-(b*z); int cstart=moleculer2/c; for(int y=cstart;y>0;y--){ int moleculer3=moleculer2; moleculer3=moleculer3-(c*y); if(moleculer3%e==0){ int x=moleculer3/e; cout<<x<<" "<<y<<" "<<z<<endl; amount++; } } } cout<<amount; } system("pause"); return 0; } |