記錄一道學長們說有點難度的題目
好好玩啊這道題
ACM程序設計大賽是大學級別最高的腦力競賽,素來被冠以"程序設計的奧林匹克"的尊稱。大賽至今已有近40年的歷史,是世界范圍內歷史最悠久、規模最大的程序設計競賽。比賽形式是:從各大洲區域預賽出線的參賽隊伍,于指定的時間、地點參加世界級的決賽,由1個教練、3個成員組成的小組應用一臺計算機解決7到13個生活中的實際問題。
現在假設你正在參加ACM程序設計大賽,這場比賽有 n 個題目,對于第 i 個題目你有 a_i 的概率AC掉它,如果你不會呢,那么這時候隊友的作用就體現出來啦,隊友甲有 b_i 的概率AC掉它, 隊友乙有 c_i 的概率AC掉它,那么現在教練想知道你們隊伍做出 x 個題目的概率。
Input
輸入一個正整數T(T<=100),表示有T組數據,對于每組數據首先輸入一個 n (7<=n<=13),表示有 n 個題目,接下來輸入三行,
第一行輸入 n 個數a_i,第二行輸入 n 個數b_i,第三行輸入 n 個數c_i, 其中 a_i, b_i, c_i 的意義如題,最后輸入一個 x 表示教練想要知道你們隊伍做出的題目數(x>=0)。
Output
輸出一行表示結果,保留4位小數
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int i,j;
double gl[4][15];
double ac[15][15];
double eror[15];
int main()
{
int zu;
while(scanf("%d",&zu)!=EOF)
{
while(zu>0)
{
int n;
scanf("%d",&n);
for(i=1;i<=3;i++)
{
for(j=1;j<=n;j++)
{
scanf("%lf",&gl[i][j]);
}
}
int x;
scanf("%d",&x);
ac[0][0]=1;
for(i=1;i<=n;i++)
{
eror[i]=(1-gl[1][i])*(1-gl[2][i])*(1-gl[3][i]);//這里是每道題錯的概率
}
for(i=1;i<=n;i++)//這里i表示的是題數
{
for(j=0;j<=i;j++)//這里j表示的是ac數
{
if(j==0)
ac[i][j]=ac[i-1][j]*(eror[i]);//第一道錯題總是要一直錯的 =^=
else
ac[i][j]=ac[i-1][j-1]*(1-eror[i])+ac[i-1][j]*eror[i];//可能是錯了也可能是對了,很有意思
}
}
if(x>n)
printf("0.0000\n");
else
printf("%.4f\n",ac[n][x]);
zu--;
}
}
//cout << "Hello world!" << endl;
return 0;
}
然后在記錄一些不懂怎么解決這個RE時我錯了好多遍的題
Give an odd number n, (1<=n<=10000001)
Given you an array which have n numbers : a[1], a[2] a[3] ... a[n].They are positive num.
There are n/2 numbers which appear twice and only one number appears once.
Now you should tell me the number which appears only once.
Input
There are several test cases end with EOF.
The first line there is a integer n.
Then the 2nd line there are n integer a[1],a[2]..a[n].
Output
For each case, output the number which appears only once.(英文出題覺得有點搞笑
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int g,ans;
int main()
{
while(~scanf("%d",&g))
{
scanf("%d",&ans);
int x;
for(int i=0;i<g-1;i++)
{
scanf("%d",&x);
ans=ans^x;
}
printf("%d\n",ans);
/*這個故事告訴我們RE了就不要再弄大數組了
直接輸入的時候就把它干掉= =
都是淚千行啊*/
}
//cout << "Hello world!" << endl;
return 0;
}
這道題也要記錄一下
上午做的思路是差不多的,電腦睡眠的時候忽然重啟
丟失了之后再寫就沒有輸出了//發現了,好烏龍的錯誤啊,要不我能多ac一道題= = 把循環中的j誤寫成了i;看來用太多循環的時候要避免i,j這兩個長得相似的--
在選舉問題中,總共有n個小團體,每個小團體擁有一定數量的選票數。如果其中m個小團體的票數和超過總票數的一半,則此組合為“獲勝聯盟”。n個團體可形成若干個獲勝聯盟。一個小團體要成為一個“關鍵加入者”的條件是:在其所在的獲勝聯盟中,如果缺少了這個小團體的加入,則此聯盟不能成為獲勝聯盟。一個小團體的權利指數是指:一個小團體在所有獲勝聯盟中成為“關鍵加入者”的次數。請你計算每個小團體的權利指數。
Input
輸入數據的第一行為一個正整數T,表示有T組測試數據。每一組測試數據的第一行為一個正整數n(0<n<=20)。第二行有n個正整數,分別表示1到n號小團體的票數。
Output
對每組測試數據,在同一個行按順序輸出1到n號小團體的權利指數。
這是學長的代碼~=……=~
#include <bits/stdc++.h> using namespace std; int n,t,i,j,s,tmp,a[21],ans[21],flag[21]; int main() { cin>>t; while(t--) { cin>>n; s=0; for(i=0;i<n;i++) {cin>>a[i];s=s+a[i];} memset(ans,0,sizeof(ans)); for(i=0;i<(1<<n);i++) { tmp=0; memset(flag,0,sizeof(flag)); for(j=0;j<n;j++) { if(i&(1<<j)) {tmp=tmp+a[j];flag[j]=1;} } if(tmp<=s/2) { for(j=0;j<n;j++) { if(tmp+a[j]>s/2&&flag[j]==0) ans[j]++; } } } for(i=0;i<=n-2;i++) printf("%d ",ans[i]); printf("%d\n",ans[n-1]); } return 0; }
我還要學好多東西呢,寫得太垃圾了
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
struct hs
{
int qz;
int piao;
int flag;
};
struct hs man[1000];
int n,i,j,temp,sum;
int main()
{
int zu;
while(cin>>zu)
{
while(zu>0)
{
sum=0;
cin>>n;
for(i=0;i<n;i++)
cin>>man[i].piao;
for(i=0;i<n;i++)
{sum=sum+man[i].piao;
man[i].qz=0;}
for(i=0;i<(1<<n);i++)
{
temp=0;
for(j=0;j<n;j++)
man[j].flag=0;
for(j=0;j<n;j++)
{
if(i&(1<<j))
{temp+=man[j].piao;
man[j].flag++;}
}
if(temp>sum/2)
{
for(j=0;j<n;j++)
{
if(man[j].flag!=0&&temp-man[j].piao<=sum/2)
man[j].qz++;
}
}
}
for(int ki=0;ki<n-1;ki++)
printf("%d ",man[ki].qz);
printf("%d\n",man[n-1].qz);
zu--;
}
}
//cout << "Hello world!" << endl;
return 0;
}
這一題也RE了= =
我和RE不得不說有仇
貼個標準答案
This time,suddenly,teacher Li wants to find out who have missed interesting DP lesson to have fun.The students who are found out will get strictly punishment.Because,teacher Li wants all the students master the DP algorithm.
However,Li doesn't want to waste the class time to call over the names of students.So he let the students to write down their names in one paper.To his satisfaction,this time, only one student has not come.
He can get the name who has not come to class,but,it is troublesome,and,teacher always have many things to think about,so,teacher Li wants you, who is in the ACM team, to pick out the name.
Input
There are several test cases.The first line of each case have one positive integer N.N is the number of the students,and N will not greater than 500,000.
Then,following N lines,each line contains one name of students who have attended class.The N-1 lines are presented after N lines.These N-1 lines indicates the names of students who have come to class this time,one name in one line.
The length of student's name is not greater than 30.
Process to the end of file.
Output
For each test case, first print a line saying "Scenario #k", where k is the number of the test case.Then output the name of the student who have not come to class.One case per line.Print a blank line after each test case, even after the last one.
(英文出題弄得我漏掉好多細節
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long int n,i;
char name[40],tmp[40];
int main(){
int cas=1;
while(~scanf("%ld",&n))
{
memset(name,0,sizeof(name));
for(i=1;i<=2*n-1;i++)
{
scanf("%s",tmp);
for(int j=0;j<40;j++)
name[j]=name[j]^tmp[j];
}
printf("Scenario #%d\n",cas++);
cout<<name<<endl<<endl;//這里特別注意,題中說每組輸出之后要有一行blank,所以多輸出一個換行:-)
}
return 0;
}
好累好累
今天的份額解決了
把昨天的補上 ;^ ;
浙公網安備 33010602011771號