暑期集训队员选拔赛

Barn Repair

Time Limit:1000MS  Memory Limit:65536K
Total Submit:63 Accepted:18

Description

It was a dark and stormy night that ripped the roof and gates off the stalls that hold Farmer John's cows. Happily, many of the cows were on vacation, so the barn was not completely full.
The cows spend the night in stalls that are arranged adjacent to each other in a long line. Some stalls have cows in them; some do not. All stalls are the same width.
Farmer John must quickly erect new boards in front of the stalls, since the doors were lost. His new lumber supplier will supply him boards of any length he wishes, but the supplier can only deliver a small number of total boards. Farmer John wishes to minimize the total length of the boards he must purchase.
Given M (1 ≤ M ≤50), the maximum number of boards that can be purchased; S (1 ≤ S ≤ 200), the total number of stalls; C (1 ≤ C ≤ S) the number of cows in the stalls, and the C occupied stall numbers (1 ≤ stall_number ≤ S), calculate the minimum number of stalls that must be blocked in order to block all the stalls that have cows in them.
Print your answer as the total number of stalls blocked.

Input

There several test cases, for each test case:
Line 1: M, S, and C (space separated)
Lines 2-C+1: Each line contains one integer, the number of an occupied stall.

Output

A single line with one integer that represents the total number of stalls blocked.

Sample Input

4 50 18
3
4
6
8
14
15
16
17
21
25
26
27
30
31
40
41
42
43

 

Sample Output

25
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{	
	return *(int *)a-*(int *)b;
}
int main()
{
	int i,j,m,s,c,sum;
	int a[201],b[201];
	while(scanf("%d%d%d",&m,&s,&c)!=-1){
		for(i=0;i<c;i++)
			scanf("%d",a+i);
		qsort(a,c,sizeof(a[0]),cmp);
		for(i=0;i<c-1;i++)	
			b[i]=a[i+1]-a[i];
		qsort(b,c-1,sizeof(b[0]),cmp);
		sum=a[c-1]-a[0]+1;
		for(i=c-m;i<c-1;i++)
			sum-=b[i]-1;
		printf("%d/n",m<c?sum:c);
	}
	return 0;
}
 

Pascal's Triangle of Death

Time Limit:1000MS  Memory Limit:65536K
Total Submit:61 Accepted:17

Description

In this problem, you are asked to generate Pascal's Triangle. Pascal's Triangle is useful in many areas from probability to polynomials to programming contests. It is a triangle of integers with ``1'' on top and down the sides. Any number in the interior equals the sum of the two numbers above it. For example, here are the first 5 rows of the triangle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
In ``Pascal's Triangle of Death,'' you are to generate a left justified Pascal's Triangle. When any number in the triangle is exceeds or equals 1060, your program should finish printing the current row and exit. The output should have each row of the triangle on a separate line with one space between each element.
The final element of each line should be directly followed by a newline. There is no space after the last number on each line.

Input

There is no input for this problem.

Output

 

Sample Input

 

Sample Output

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
.
.
.
etc.

 

Source

UVa

 

 

#include<stdio.h> #include<string.h> #define M 350 char map[M][M][65]; void add(char *a,char *b,char *c) { int l1,l2,i; l1=strlen(a); l2=strlen(b); memset(c,0,65); for(i=0;i<l1&&i<l2;i++){ c[i]=a[l1-1-i]+b[l2-1-i]-'0'; } if(l1<l2){ while(i<l2) c[i++]=b[l2-1-i]; } else{ while(i<l1) c[i++]=a[l1-1-i]; } for(i=0;i<65;i++){ if(c[i+1]==0) break; if(c[i]>'9'){ c[i]-=10; c[i+1]+=1; } } if(c[i]>'9'){ c[i]-=10; c[i+1]='1'; } strrev(c); } int main() { int i,j,flag=1; printf("1/n"); for(i=0;i<M;i++){ for(j=0;j<M;j++) memset(map[i][j],0,65); } strcpy(map[1][1],"1"); for(i=2;flag;i++){ for(j=1;j<=i;j++){ add(map[i-1][j],map[i-1][j-1],map[i][j]); printf(j<i?"%s ":"%s/n",map[i][j]); if(strlen(map[i][j])>=61) flag=0; } } printf("/n"); return 0; }/* int main() { char *a="19990",*b="21056",c[100]; add(a,b,c); printf("%s %d/n",c,strlen(c)); getchar(); return 0; }*/

 

 

 

迷宫

Time Limit:1000MS  Memory Limit:65536K
Total Submit:35 Accepted:16

Description

一天,birdfly遇到了上帝,上帝说:“现在我要考验你,天下有一迷宫。此迷宫呈正方形,迷宫被墙分成很多相同的单元房。每两个相邻的单元房都有一个门,现在我把你送入坐标为(1, 1)的房间内,你要走到坐标为(n, n)的房间去,每个房间里都被赋予一个运气值k,如果为正数,表示你会得到相应的金币数,如果为0表示你不得不亏,如果是负数表示你要失去相应的金币数。”上帝正准备走,迟疑了一下补充道:“记住,每个房间只能走一次。”说完,匆匆离去。birdfly一想,如果相邻的房子里有最多的金币也不一定要进去,因为进去了又不能再回到刚才的房间,如果那个房间旁边里运气值都为负数,那就可能要失去更多金币。所以,现在他想请你帮帮忙,他不贪心,他不打算得到一些金币,但他也不想失去,所以他想知道有没有可能到达(n, n)这个房间的时候,不得也不失。注意: (1, 1)和(n, n)这两个位置的运气值也得加上,因为它毕竟到过这两个个房间;不得也不失,即为总的运气值的和为0。呵呵,加油啊!他很期待你的帮助!

Input

多组测试实例。每组首先一个整数n (2 ≤ n ≤ 5),表示迷宫的边长,接下来有n行n列个整数,第i行第j列的整数vij表示坐标为(i, j)的房间里的运气值为vij( |vij| ≤ 100)

Output

如描述,如果可能不得也不失,输出YES,否者输出NO。

Sample Input

3
2 0 -2
3 4 -4
0 -3 4
2
2 3
-3 4

 

Sample Output

YES
NO

 

Source

Birdfly

#include<stdio.h> #include<string.h> #include<stdlib.h> int dir[][2]={{0,1},{1,0},{0,-1},{-1,0}}; int flag,n; int map[6][6]; int vis[6][6]; void dfs(int x,int y,int luky) { int i,j,temp; if(flag) return ; if(x<1||x>n||y<1||y>n||vis[x][y]) return ; /*for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ printf(j<n?"%d ":"%d/n",vis[i][j]); } } printf("/n"); getchar();*/ vis[x][y]=1; luky+=map[x][y]; if(x==n&&y==n){ if(luky==0){ flag=1; return ; } vis[x][y]=0; return ; } for(i=0;i<4;i++) dfs(x+dir[i][0],y+dir[i][1],luky); vis[x][y]=0; return ; } int main() { int i,j; while(scanf("%d",&n)!=EOF){ for(i=1;i<=n;i++){ for(j=1;j<=n;j++) scanf("%d",&map[i][j]); } memset(vis,0,sizeof(vis)); flag=0; dfs(1,1,0); printf(flag?"YES/n":"NO/n"); } return 0; }

你可能感兴趣的:(暑期集训队员选拔赛)