By SinGuLaRiTy
For All :Time Limit: 1s | Memory: 256MB
第一题:考试得分(score)[najboljih]
【题目描述】
某单位举办了一次考试,考试有8道题,每道题的得分不一样。选手可以随便做,但最后只统计5道题的得分。现在给出选手每道题的得分,求出他最后的得分最大是多少?
【输入】
8行,每行一个正整数X(0<=X<=150),第i个X表示第i道题的得分。
【输出】
第一行:该选手最后的得分。
第二行:按升序给出的选入计分的5道题的题号。
【样例输入】20
30
50
48
33
66
0
64
【样例输出】
261
3 4 5 6 8
【简单题解】
大水题
【STD Code】
#include<cstring>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct node
{
int order;
int value;
};
node num[10];
int sto[10];
int cnt=1;
bool cmp(node x,node y)
{
if(x.value<y.value)
return 1;
return 0;
}
int main()
{
freopen("score.in","r",stdin);
freopen("score.out","w",stdout);
int Ans=0;
for(register int i=1;i<=8;i++)
{
scanf("%d",&num[i].value);
num[i].order=i;
}
sort(num+1,num+9,cmp);
for(register int i=4;i<=8;i++)
{
Ans+=num[i].value;
sto[cnt]=num[i].order;
cnt++;
}
printf("%d\n",Ans);
sort(sto+1,sto+6);
for(int i=1;i<=5;i++)
{
printf("%d ",sto[i]);
}
return 0;
}
【International Edition】
The Croatian version of this contest has the following rules: “Each round of the contest consists of 8
tasks with different point values. Every contestant may solve any of the tasks they choose. However, the
contestant’s final score will be the sum of points earned on any 5 tasks such that this sum is maximized.”
Since the organizers were busy coming up with interesting problems for the contest (and translating
them), they’ve simply forgotten to solve the problem of determining the points scored by each
contestant. Now they are kindly asking you to do it for them.
Write a program that, given the number of points earned by a contestant on each task, determines the
total amount of points scored by that contestant, as well as the sorted list of the 5 problems counting
towards that score. No contestant will ever score the same amount of points on two different
problems.
INPUT
Input consists of 8 lines. Each line of input contains a single positive integer X (0 ≤ X ≤ 150), wherethe number X in row i denotes the number of points earned by the contestant on problem i. All 8
numbers X will be distinct.
OUTPUT
The first line of output must contain the total amount of points scored by the contestant.The second line of output must contain indices of the 5 problems counting towards the total score,
sorted in ascending order, separated by single spaces. Problem indices are positive integers from 1 to
8, inclusive.
SCORING
If only the first line of output (the total amount of points) is correct, the solution will be awarded 40%of points on that test case (even if the second line of output is not present).
第二题:死胡同(deadend)[okret]
【题目描述】
Mirko学会了开车,但是他还不会在狭窄的街道上掉头。所以,他只能找一个禁止掉头的城镇开车。现在他已经拿到了一个城镇的地图。这个城镇可以看做是R*C的一个表格,每个格子要么为’X’,要么为’.’。’X’表示建筑的一部分,‘.’表示道路。你可以从当前格子往上下左右四个方向移动,当然,‘X’是不能进入的。如果从城镇的任一点出发,你都能找到一条路径回到原点,则认为该城镇没有死胡同,否则该城镇有死胡同,不适合Mirko开车。
【输入】
第一行包含两个整数R和C(3<=R,C<=10),表示城镇地图的行数和列数。
接下来有R行,每行C个字符,要么为’X’,要么为’.’。’X’表示建筑的一部分,‘.’表示道路。
至少有两个格子为‘.’,且保证所有‘.’都是联通的。
【输出】
唯一的一行,如果没有死胡同,输出0,否则输出1.
【样例输入】4 3
XXX
X.X
X.X
XXX
【样例输出】1
【简单题解】
大水题,注意特殊情况即可。
【STD Code】
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int city[20][20];
int model[20][20];
char data[20];
int X,R;
int step_cnt=-1;
int flag=1;
void reset()
{
for(register int i=1;i<=X;i++)
for(register int j=1;j<=R;j++)
{
model[i][j]=city[i][j];
}
}
void DFS(int x,int y)
{
step_cnt++;
if(step_cnt>1&&(model[x+1][y]==3||model[x-1][y]==3||model[x][y+1]==3||model[x][y-1]==3))
flag=0;
if(model[x][y]!=3)
model[x][y]=0;
if(model[x+1][y]==1)//up
{
DFS(x+1,y);
}
if(model[x-1][y]==1)//down
{
DFS(x-1,y);
}
if(model[x][y-1]==1)//left
{
DFS(x,y-1);
}
if(model[x][y+1]==1)//right
{
DFS(x,y+1);
}
}
int main()
{
scanf("%d%d",&X,&R);
for(register int i=1;i<=X;i++)
{
scanf("%s",data+1);
for(register int j=1;j<=R;j++)
{
city[i][j]=(data[j]=='X' ? 0 : 1);
}
}
for(register int i=1;i<=X;i++)
for(register int j=1;j<=R;j++)
{
if(city[i][j]!=0)
{
reset();
model[i][j]=3;
DFS(i,j);
if(flag==1)
{
printf("1");
return 0;