POJ 1029 硬幣稱量類型二 與POJ 1013類比 類比題

來源:互聯網
上載者:User

參考了slayer 的解答http://www.slyar.com/blog/poj-1029-cpp.html  與POJ 1013類比

類比題,抓兩點,其一在等式中出現的硬幣一定不是假幣,其二在不等式中每次都出現即在不等式中出現的次數等於它出現的次數,一定是假幣

其他情況無法判斷輸出0

#include <iostream><br />#include <string><br />using namespace std;<br />const int MAX = 1001;<br />int main(){<br />int i,n,k,p,count,pos,total = 0;//total標記不等式出現的次數,不等式中假幣一定都出現<br />char sign;<br />int t[MAX] = {0};//記錄稱量的未經處理資料<br />int r[MAX] = {0};//標記硬幣真假<br />int w[MAX] = {0};//標記硬幣重量<br />cin>>n>>k;<br />while (k--)<br />{<br />cin>>p;<br />for ( i = 0;i < 2*p;i++)<br />cin>>t[i];<br />cin>>sign;<br />if (sign == '=')//在等式中出現的一定是真的<br />{<br />for ( i = 0;i < 2*p;i++)<br />r[t[i]] = 1;<br />}</p><p>else if (sign == '<')<br />{<br />total++;<br />for (i = 0; i < p; i++)<br />w[t[i]]--;<br />for (i = p;i < 2*p; i++)<br />w[t[i]]++;<br />}<br />else if (sign == '>')<br />{<br />total++;<br />for (i = 0; i < p; i++)<br />w[t[i]]++;<br />for (i = p;i < 2*p; i++)<br />w[t[i]]--;<br />}<br />}<br />count = 0,pos = 0;<br />for (i = 1;i <= n;i++)//注意硬幣從1開始標號<br />{<br />if (r[i])<br />{<br />continue;<br />}<br />if (w[i] == total || w[i] == -total)<br />{<br />pos = i;<br />count++;<br />}<br />}<br />if (count != 1)<br />{<br />cout<<0<<endl;<br />}<br />else cout<<pos<<endl;<br />return 0;<br />} 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.