日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

老BOJ 11 Counting

發布時間:2024/9/30 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 老BOJ 11 Counting 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Counting
Accept:100????Submit:807
Time Limit:2000MS????Memory Limit:65536KB

Description

?

We are familiar with the game called “Counting 24”. Now it comes a problem that we want to know whether we can figure out the exact answer with given 4 numbers only using +,-,*,/ and (,).

?

Input

There are several cases in a test. Each case contains only 5 integers, a1, a2, a3, a4 and required answer. All integers are positive and no more than 100.

Output

If it is possible to figure out the required answer, output “Possible”; otherwise output “Impossible”.

Sample Input

?

5 5 1 5 24

?

Sample Output

?

Impossible


#include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> #include<set> using namespace std; int a[4],ans; set<int>s[16]; set<int>::iterator it1,it2; inline void deal(int x,int tmp){s[x].insert(tmp);} void cal(int x){if(!s[x].empty())return;for(int i=1;i<16;i++)if((x&i)==i)for(it1=s[i].begin();it1!=s[i].end();it1++)for(it2=s[x-i].begin();it2!=s[x-i].end();it2++){deal(x,(*it1)+(*it2));deal(x,(*it1)*(*it2));deal(x,(*it1)-(*it2));if((*it2)&&(*it1)%(*it2)==0)deal(x,(*it1)/(*it2));} } bool can(){int i;for(i=0;i<16;i++)s[i].clear();for(i=0;i<4;i++)s[1<<i].insert(a[i]);for(i=1;i<16;i++)cal(i);return s[15].find(ans)==s[15].end()?false:true; } int main(){while(~scanf("%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&ans))printf("%s\n",can()?"Possible":"Impossible");return 0; }

總結

以上是生活随笔為你收集整理的老BOJ 11 Counting的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。