2014
02-12

# Life

Samuel,Former Zua leader,was arrested and had to stay in prison during the Spring Festival. He was in custody for money laundering and other cases.
According to the report,Samuelwas alleged to have embezzled 104 million New Zua dollars ($3.15 million) in public funds, accepted bribes of about$9 million in a land purchase deal, and taken a kickback of \$2.7 million from a construction project.
Although Samuel is a smart lawyer,he was still arrested due to his illegal actions.
Now Samuel has a question for you:If you are given the legislations of Zua,can you tell how many years he stay in the prison?
The legislations of Zua are supposed as the following few lines:

Input will contains 3 parts. There is an integer t in the first line meaning t test cases. Then the next line has 2 parts:n(represents the cases Samuel was accused with),s(a string with the length of n,only contains “0”,”1”.Here ‘0’means he was not accused with this case,and ‘1’means he was accused with this case ) .The next n lines have the numbers of New Zua dollars(the unit is million) he was accused with.

Input will contains 3 parts. There is an integer t in the first line meaning t test cases. Then the next line has 2 parts:n(represents the cases Samuel was accused with),s(a string with the length of n,only contains “0”,”1”.Here ‘0’means he was not accused with this case,and ‘1’means he was accused with this case ) .The next n lines have the numbers of New Zua dollars(the unit is million) he was accused with.

2
3
011
10 5 15
5
01101
1 10 10 100 31 

Samuel was accused with 2 case(s),and he will stay in the prison for 5 year(s).
Samuel was accused with 3 case(s),and he will stay in the prison for 20 year(s).

A Bug’s Life

Time Limit: 10000MS Memory Limit:
65536K

Total Submissions: 25599 Accepted:
8332

Description

Background

Professor Hopper is researching the sexual behavior of a rare
species of bugs. He assumes that they feature two different genders
and that they only interact with bugs of the opposite gender. In
his experiment, individual bugs and their interactions were easy to
identify, because numbers were printed on their
backs.

Problem

Given a list of bug interactions, decide whether the
experiment supports his assumption of two genders with no
homosexual bugs or if it contains some bug interactions that
falsify it.

Input

The first line of the input contains the number of scenarios.
Each scenario starts with one line giving the number of bugs (at
least one, and up to 2000) and the number of interactions (up to
1000000) separated by a single space. In the following lines, each
interaction is given in the form of two distinct bug numbers
separated by a single space. Bugs are numbered consecutively
starting from one.

Output

The output for every scenario is a line containing “Scenario
#i:”, where i is the number of the scenario starting at 1, followed
by one line saying either “No suspicious bugs found!” if the
experiment is consistent with his assumption about the bugs’ sexual
behavior, or “Suspicious bugs found!” if Professor Hopper’s
assumption is definitely wrong.

Sample
Input

2

3 3

1 2

2 3

1 3

4 2

1 2

3 4

Sample
Output

Scenario #1:

Suspicious bugs found!

Scenario #2:

No suspicious bugs found!

Hint

Huge input,scanf is recommended.

Source

TUD Programming Contest 2005, Darmstadt, Germany

const
maxn=2000;
var
f,v:array[0..maxn]of longint;
t,i:longint;
function find(x:longint):longint;
var
k:longint;
begin
if f[x]=x then exit(x);
k:=f[x];
f[x]:=find(f[x]);
v[x]:=(v[x]+v[k])and 1;
exit(f[x]);
end;
procedure work;
var
n,m,i,j,k,x,y:longint;
begin
fillchar(f,sizeof(f),0);
fillchar(v,sizeof(v),0);
for i:=1 to n do
f[i]:=i;
for i:=1 to m do
begin
if find(x)=find(y) then
if (v[x]+v[y])and 1<>1 then
begin
writeln('Suspicious bugs found!');
for j:=i+1 to m do
exit;
end;
k:=v[x];
x:=f[x];
f[x]:=f[y];
v[x]:=((k+v[y])+1)and 1;
end;
writeln('No suspicious bugs found!');
end;
begin
for i:=1 to t do
begin
writeln('Scenario #',i,':');
work;
writeln;
end;
end.


1. 嗯 分析得很到位，确实用模板编程能让面试官对你的印象更好。在设置辅助栈的时候可以这样：push时，比较要push的elem和辅助栈的栈顶，elem<=min.top()，则min.push(elem).否则只要push（elem）就好。在pop的时候，比较stack.top()与min.top(),if(stack.top()<=min.top()),则{stack.pop();min.pop();}，否则{stack.pop();}.

2. 学算法中的数据结构学到一定程度会乐此不疲的，比如其中的2－3树，类似的红黑树，我甚至可以自己写个逻辑文件系统结构来。

3. #include <stdio.h>
int main()
{
int n,p,t[100]={1};
for(int i=1;i<100;i++)
t =i;
while(scanf("%d",&n)&&n!=0){
if(n==1)
printf("Printing order for 1 pages:nSheet 1, front: Blank, 1n");
else {
if(n%4) p=n/4+1;
else p=n/4;
int q=4*p;
printf("Printing order for %d pages:n",n);
for(int i=0;i<p;i++){
printf("Sheet %d, front: ",i+1);
if(q>n) {printf("Blank, %dn",t[2*i+1]);}
else {printf("%d, %dn",q,t[2*i+1]);}
q–;//打印表前
printf("Sheet %d, back : ",i+1);
if(q>n) {printf("%d, Blankn",t[2*i+2]);}
else {printf("%d, %dn",t[2*i+2],q);}
q–;//打印表后
}
}
}
return 0;
}