Description
The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.
Help the park administration count the number of ways to place the benches.
Input
The only line of the input contains one integer n (5 ≤ n ≤ 100) — the number of east to west paths and north to south paths.
Output
Output one integer — the number of ways to place the benches.
Sample Input
5
120
题解:给公园装凳子,每个十字路口就一个,同行列就一个凳子,问多少种方法;
从行和列中分别选5个就是五个凳子安放的位置,然后5*5的格子有5!种方法;所以就是5!*C(n,5)*C(n,5);
ps:第一次用C#写一下,竟然就过了。。。跟C语言真像;
代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 输入输出 { class Program { static void Main(string[] args) { long ans = 1; int n; string s = Console.ReadLine(); n = int.Parse(s); for (int i = 1; i <= 5; i++) { ans = ans * (n - i + 1) / i * (n - i + 1) / i; } ans *= 120; Console.WriteLine("{0:d}", ans); } } }
Description
Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem.
A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will look like following: a game designer will select a rectangular area on the map, and each cell whose center belongs to the selected rectangle will be filled with the enemy unit.
More formally, if a game designer selected cells having coordinates (x1, y1) and (x2, y2), where x1 ≤ x2 and y1 ≤ y2, then all cells having center coordinates (x, y) such that x1 ≤ x ≤ x2 and y1 ≤ y ≤ y2 will be filled. Orthogonal coordinates system is set up so that one of cell sides is parallel to OX axis, all hexagon centers have integer coordinates and for each integer x there are cells having center with such x coordinate and for each integer y there are cells having center with such y coordinate. It is guaranteed that difference x2 - x1is divisible by 2.
Working on the problem Petya decided that before painting selected units he wants to output number of units that will be painted on the map.
Help him implement counting of these units before painting.
Input
The only line of input contains four integers x1, y1, x2, y2 ( - 109 ≤ x1 ≤ x2 ≤ 109, - 109 ≤ y1 ≤ y2 ≤ 109) — the coordinates of the centers of two cells.
Output
Output one integer — the number of cells to be filled.
Sample Input
1 1 5 5
13
题解:给出两个点 x1 ≤ x ≤ x2 and y1 ≤ y ≤ y2,这些点为中心的6边型会被覆盖,问覆盖多少个,由于x轴差值必然是2的倍数,所以x轴覆盖的肯定是(x2-x1)/2+1;y则要考虑奇偶的问题;
很好推的;
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<map> #include<string> #include<vector> using namespace std; const int INF=0x3f3f3f3f; #define SI(x) scanf("%d",&x) #define PI(x) printf("%d",x) #define P_ printf(" ") #define mem(x,y) memset(x,y,sizeof(x)) typedef __int64 LL; int main(){ LL x1,x2,y1,y2,x,y; while(~scanf("%I64d%I64d%I64d%I64d",&x1,&y1,&x2,&y2)){ x=abs(x2-x1)/2+1;y=abs(y2-y1)/2; if(y1||y2)y++; LL ans; if(y==0)ans=x; else ans=x*y+(x-1)*(y-1); printf("%I64d\n",ans); } return 0; }
Description
Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting feature gets "I suggested a new feature" pennant on his table.
Because of the limited budget of the new reward system only 5 "I fixed a critical bug" pennants and 3 "I suggested a new feature" pennants were bought.
In order to use these pennants for a long time they were made challenge ones. When a man fixes a new critical bug one of the earlier awarded "I fixed a critical bug" pennants is passed on to his table. When a man suggests a new interesting feature one of the earlier awarded "I suggested a new feature" pennants is passed on to his table.
One man can have several pennants of one type and of course he can have pennants of both types on his table. There are n tables in the IT company. Find the number of ways to place the pennants on these tables given that each pennant is situated on one of the tables and each table is big enough to contain any number of pennants.
Input
The only line of the input contains one integer n (1 ≤ n ≤ 500) — the number of tables in the IT company.
Output
Output one integer — the amount of ways to place the pennants on n tables.
Sample Input
2
24
题解:题目让在桌子上放两种奖状,一种有5个,一种有3个,n张桌子有几种方法,想了好久竟然是错的;
直接选桌子放广告就好了;
C#代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ChallengePennants { class Program { static long Cout(int n,int t){ long x=1; for (int i = 1; i <= t; i++) { x = x * (n - i + 1) / i; } return x; } static void Main(string[] args) { long ans = 1; int n; string s = Console.ReadLine(); n = int.Parse(s); ans *= Cout(n, 5) + Cout(4, 1) * Cout(n, 4) + Cout(n, 3) * Cout(3, 1) * 2 + 2 * Cout(2, 1) * Cout(n, 2) + Cout(n, 1); ans *= Cout(n, 3) + Cout(2,1)* Cout(n, 2) + Cout(n, 1); Console.WriteLine("{0:d}", ans); } } }
Description
To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.
The parking lot before the office consists of one line of (2n - 2) parking spaces. Unfortunately the total number of cars is greater than the parking lot capacity. Furthermore even amount of cars of each make is greater than the amount of parking spaces! That's why there are no free spaces on the parking lot ever.
Looking on the straight line of cars the company CEO thought that parking lot would be more beautiful if it contained exactly nsuccessive cars of the same make. Help the CEO determine the number of ways to fill the parking lot this way.
Input
The only line of the input contains one integer n (3 ≤ n ≤ 30) — the amount of successive cars of the same make.
Output
Output one integer — the number of ways to fill the parking lot by cars of four makes using the described way.
Sample Input
3
24
Hint
Let's denote car makes in the following way: A — Aston Martin, B — Bentley, M — Mercedes-Maybach, Z — Zaporozhets. For n = 3there are the following appropriate ways to fill the parking lot: AAAB AAAM AAAZ ABBB AMMM AZZZ BBBA BBBM BBBZ BAAA BMMM BZZZ MMMA MMMB MMMZ MAAA MBBB MZZZ ZZZA ZZZB ZZZM ZAAA ZBBB ZMMM
Originally it was planned to grant sport cars of Ferrari, Lamborghini, Maserati and Bugatti makes but this idea was renounced because it is impossible to drive these cars having small road clearance on the worn-down roads of IT City.
题解:排列组合题:题意是给放车,长度为2*n-2;中间有连续n辆车颜色相同;4种颜色;把这4辆连续颜色相同的车看成一辆,则有n-1辆,有一辆
跟旁边的颜色不同,考虑这个车在两端,以及中间的情况;则
ans=2*C(4,1)*C(3,1)*4^(n-3)+C(n-3,1)*C(4,1)*C(3,1)*C(3,1)*4^(n-4);
C#代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ChallengePennants { class Program { static void Main(string[] args) { string s = Console.ReadLine(); int n = int.Parse(s); if (n == 3) { Console.WriteLine("24"); } else { long ans=1; int temp = n - 3; while (temp!=0) { ans *= 4; temp--; } ans *= (long)9 * (n - 3) + 24; Console.WriteLine("{0:d}",ans); } } } }