2016ACM/ICPC亚洲区青岛站(区域赛练习)

本文深入解析了五种比赛算法题目,包括遗物发现的成本计算、口袋魔方的一步还原判断、彩色Pocky棒的期望吃法次数、幸运硬币的概率预测及编码竞赛中的网络稳定性优化。文章提供了详细的算法思路与代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

比赛链接:https://cn.vjudge.net/contest/257341

目录

A - Relic Discovery

B—Pocket Cube

C - Pocky

D-Lucky Coins

G-Coding Contest


A - Relic Discovery

Recently, paleoanthropologists have found historical remains on an island in the Atlantic Ocean. The most inspiring thing is that they excavated in a magnificent cave and found that it was a huge tomb. Inside the construction,researchers identified a large number of skeletons, and funeral objects including stone axe, livestock bones and murals. Now, all items have been sorted, and they can be divided into N types. After they were checked attentively, you are told that there are AiAi items of the i-th type. Further more, each item of the i-th type requires BiBi million dollars for transportation, analysis, and preservation averagely. As your job, you need to calculate the total expenditure. 

Input

The first line of input contains an integer T which is the number of test cases. For each test case, the first line contains an integer N which is the number of types. In the next N lines, the i-th line contains two numbers AiAi and BiBi as described above. All numbers are positive integers and less than 101.

Output

For each case, output one integer, the total expenditure in million dollars. 

Sample Input

1
2
1 2
3 4

Sample Output

14

没啥好说的!

 

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
using namespace std;
int main()
{
	int t,n,a,b;
	long long int sum=0;
	scanf("%d",&t);
	while(t--)
	{
		sum=0;
		scanf("%d",&n);
		for(int i=0;i<n;i++)
		{
			scanf("%d%d",&a,&b);
			sum=sum+(a*b);
		}
		printf("%lld\n",sum);
	}
	return 0;
}

B—Pocket Cube

The Pocket Cube, also known as the Mini Cube or the Ice Cube, is the 2 × 2 × 2 equivalence of a Rubik’s Cube. 
The cube consists of 8 pieces, all corners. 
Each piece is labeled by a three dimensional coordinate (h, k, l) where h, k, l ∈ {0, 1}. Each of the six faces owns four small faces filled with a positive integer. 
For each step, you can choose a certain face and turn the face ninety degrees clockwise or counterclockwise. 
You should judge that if one can restore the pocket cube in one step. We say a pocket cube has been restored if each face owns four same integers. 

Input

The first line of input contains one integer N(N ≤ 30) which is the number of test cases. 
For each test case, the first line describes the top face of the pocket cube, which is the common 2 × 2 face of pieces 
labelled by (0, 0, 1),(0, 1, 1),(1, 0, 1),(1, 1, 1). Four integers are given corresponding to the above pieces. 
The second line describes the front face, the common face of (1, 0, 1),(1, 1, 1),(1, 0, 0),(1, 1, 0). Four integers are 
given corresponding to the above pieces. 
The third line describes the bottom face, the common face of (1, 0, 0),(1, 1, 0),(0, 0, 0),(0, 1, 0). Four integers are 
given corresponding to the above pieces. 
The fourth line describes the back face, the common face of (0, 0, 0),(0, 1, 0),(0, 0, 1),(0, 1, 1). Four integers are 
given corresponding to the above pieces. 
The fifth line describes the left face, the common face of (0, 0, 0),(0, 0, 1),(1, 0, 0),(1, 0, 1). Four integers are given 
corresponding to the above pieces. 
The six line describes the right face, the common face of (0, 1, 1),(0, 1, 0),(1, 1, 1),(1, 1, 0). Four integers are given 
corresponding to the above pieces. 
In other words, each test case contains 24 integers a, b, c to x. You can flat the surface to get the surface development 
as follows. 

+ - + - + - + - + - + - +
| q | r | a | b | u | v |
+ - + - + - + - + - + - +
| s | t | c | d | w | x |
+ - + - + - + - + - + - +
        | e | f |
        + - + - +
        | g | h |
        + - + - +
        | i | j |
        + - + - +
        | k | l |
        + - + - +
        | m | n |
        + - + - +
        | o | p |
        + - + - +

Output

For each test case, output YES if can be restored in one step, otherwise output NO.

Sample Input

4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
6 6 6 6
1 1 1 1
2 2 2 2
3 3 3 3
5 5 5 5
4 4 4 4
1 4 1 4
2 1 2 1
3 2 3 2
4 3 4 3
5 5 5 5
6 6 6 6
1 3 1 3
2 4 2 4
3 1 3 1
4 2 4 2
5 5 5 5
6 6 6 6

Sample Output

YES
YES
YES
NO

自己的模拟能力很差:参考网址 https://blog.youkuaiyun.com/mrlry/article/details/53410577

模拟魔方转化,把魔方转一步,就能使得魔方的每个面的四个格子内的颜色都相同。

用数组存放魔方的数据,用数组数据的同异来模仿魔方的转动。

#include <cstring>
#include <cstdio>
#include <string.h>
#include <iostream>
#include <cmath>
using namespace std;
int com(int a,int b,int c,int d)
{

    if(a==b&&b==c&&c==d) return 1;
    else return 0;
}
int main()
{
   int cas;
   int mark;
   scanf("%d",&cas);
   while(cas--)
   {
       mark=0;
       int a[8][5];
       int b[25];
       int i,j;
       for(int i=1;i<=6;i++)
       {
           for(j=1,b[i]=1;j<=4;j++)
           {
               scanf("%d",&a[i][j]);
               if(j>=2)
               {
                   if(a[i][j]!=a[i][j-1])
                        b[i]=0;
               }
           }
           //printf("b[%d]=%d\n",i,b[i]);
       }
       
	   
       //if(com(a[1][1],a[1][2],a[1][3],a[1][4])&&com(a[2][1],a[2][2],a[2][3],a[2][4])&&com(a[3][1],a[3][2],a[3][3],a[3][4])&&com(a[4][1],a[4][2],a[4][3],a[4][4])&&com(a[5][1],a[5][2],a[5][3],a[5][4])&&com(a[6][1],a[6][2],a[6][3],a[6][4])) mark=1;
       if(com(a[1][1],a[1][2],a[1][3],a[1][4])&&com(a[2][1],a[2][2],a[2][3],a[2][4])&&com(a[3][1],a[3][2],a[3][3],a[3][4])&&com(a[4][1],a[4][2],a[4][3],a[4][4])&&com(a[5][1],a[5][2],a[5][3],a[5][4])&&com(a[5][1],a[5][2],a[5][3],a[5][4])) mark=1;
       if(b[1]&&b[3]&&com(a[2][1],a[2][2],a[5][1],a[5][3])&&com(a[6][1],a[6][3],a[2][3],a[2][4])&&com(a[5][2],a[5][4],a[4][1],a[4][2])&&com(a[4][3],a[4][4],a[6][4],a[6][2])) mark=1;
       if(b[1]&&b[3]&&com(a[4][1],a[4][2],a[6][1],a[6][3])&&com(a[4][3],a[4][4],a[5][1],a[5][3])&&com(a[5][2],a[5][4],a[2][3],a[2][4])&&com(a[2][1],a[2][2],a[6][4],a[6][2])) mark=1;

       if(b[5]&&b[6]&&com(a[1][2],a[1][4],a[2][1],a[2][3])&&com(a[2][2],a[2][4],a[3][1],a[3][3])&&com(a[3][2],a[3][4],a[4][3],a[4][1])&&com(a[4][4],a[4][2],a[1][3],a[1][1])) mark=1;
       if(b[5]&&b[6]&&com(a[2][2],a[2][4],a[1][1],a[1][3])&&com(a[1][2],a[1][4],a[4][3],a[4][1])&&com(a[4][4],a[4][2],a[3][1],a[3][3])&&com(a[3][2],a[3][4],a[2][1],a[2][3])) mark=1;

       if(b[2]&&b[4]&&com(a[1][1],a[1][2],a[6][3],a[6][4])&&com(a[6][1],a[6][2],a[3][1],a[3][2])&&com(a[3][3],a[3][4],a[5][3],a[5][4])&&com(a[5][1],a[5][2],a[1][3],a[1][4])) mark=1;
       if(b[2]&&b[4]&&com(a[1][1],a[1][2],a[5][3],a[5][4])&&com(a[5][1],a[5][2],a[3][1],a[3][2])&&com(a[3][3],a[3][4],a[6][3],a[6][4])&&com(a[6][1],a[6][2],a[1][3],a[1][4])) mark=1;

       if(mark)
        printf("YES\n");
       else
        printf("NO\n");
   }
   return 0;
}

 

C - Pocky

Let’s talking about something of eating a pocky. Here is a Decorer Pocky, with colorful decorative stripes in the coating, of length L. 
While the length of remaining pocky is longer than d, we perform the following procedure. We break the pocky at any point on it in an equal possibility and this will divide the remaining pocky into two parts. Take the left part and eat it. When it is not longer than d, we do not repeat this procedure. 
Now we want to know the expected number of times we should repeat the procedure above. Round it to 6 decimal places behind the decimal point. 

Input

The first line of input contains an integer N which is the number of test cases. Each of the N lines contains two float-numbers L and d respectively with at most 5 decimal places behind the decimal point where 1 ≤ d, L ≤ 150. 

Output

For each test case, output the expected number of times rounded to 6 decimal places behind the decimal point in a line.

Sample Input

6
1.0 1.0
2.0 1.0
4.0 1.0
8.0 1.0
16.0 1.0
7.00 3.00

Sample Output

0.000000
1.693147
2.386294
3.079442
3.772589
1.847298

 

找规律吧!

log以e为底2的对数等于0.693147 。

 

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<math.h>
using namespace std;
int main()
{
    int t;
    double l,d;
    scanf("%d",&t);
    while(t--)
    {
    	scanf("%lf%lf",&l,&d);
    	if(l<=d)
    	  puts("0.000000");
    	else
    	{
    		printf("%.6lf\n",log(l/d)+1);
		}
	}
	return 0;
}

 

D-Lucky Coins

Bob has collected a lot of coins in different kinds. He wants to know which kind of coins is lucky. He finds out a lucky kind of coins by the following way. He tosses all the coins simultaneously, and then removes the coins that come up tails. He then tosses all the remaining coins and removes the coins that come up tails. He repeats the previous step until there is one kind of coins remaining or there are no coins remaining. If there is one kind of coins remaining, then this kind of coins is lucky. Given the number of coins and the probability that the coins come up heads after tossing for each kind, your task is to calculate the probability for each kind of coins that will be lucky. 

Input

The first line is the number of test cases. For each test case, the first line contains an integer k representing the number of kinds. Each of the following k lines describes a kind of coins, which contains an integer and a real number representing the number of coins and the probability that the coins come up heads after tossing. It is guaranteed that the number of kinds is no more than 10, the total number of coins is no more than 1000000, and the probabilities that the coins come up heads after tossing are between 0.4 and 0.6.

Output

For each test case, output a line containing k real numbers with the precision of 6 digits, which are the probabilities of each kind of coins that will be lucky. 

Sample Input

3
1
1000000 0.5
2
1 0.4
1 0.6
3
2 0.4
2 0.5
2 0.6

Sample Output

1.000000
0.210526 0.473684
0.124867 0.234823 0.420066

概率 数学推导

 

 

 

G-Coding Contest

 

A coding contest will be held in this university, in a huge playground. The whole playground would be divided into N blocks, and there would be M directed paths linking these blocks. The i-th path goes from the uiui-th block to the vivi-th block. Your task is to solve the lunch issue. According to the arrangement, there are sisicompetitors in the i-th block. Limited to the size of table, bibi bags of lunch including breads, sausages and milk would be put in the i-th block. As a result, some competitors need to move to another block to access lunch. However, the playground is temporary, as a result there would be so many wires on the path. 
For the i-th path, the wires have been stabilized at first and the first competitor who walker through it would not break the wires. Since then, however, when a person go through the i - th path, there is a chance of pipi to touch 
the wires and affect the whole networks. Moreover, to protect these wires, no more than cici competitors are allowed to walk through the i-th path. 
Now you need to find a way for all competitors to get their lunch, and minimize the possibility of network crashing. 

Input

The first line of input contains an integer t which is the number of test cases. Then t test cases follow. 
For each test case, the first line consists of two integers N (N ≤ 100) and M (M ≤ 5000). Each of the next N lines contains two integers si and bibi (sisi , bibi ≤ 200). 
Each of the next M lines contains three integers uiui , vivi and ci(cici(ci ≤ 100) and a float-point number pipi(0 < pipi < 1). 
It is guaranteed that there is at least one way to let every competitor has lunch.

Output

For each turn of each case, output the minimum possibility that the networks would break down. Round it to 2 digits.

Sample Input

1
4 4
2 0
0 3
3 0
0 3
1 2 5 0.5
3 2 5 0.5
1 4 5 0.5
3 4 5 0.5

Sample Output

0.50

费用流

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值