2016ACM/ICPC亚洲区大连站(区域赛练习)

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

 

目录

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

A-Wrestling Match

D-A Simple Math Problem

F-Detachment

H - To begin or not to begin 

I - Convex

J - Find Small A


A-Wrestling Match

 

Nowadays, at least one wrestling match is held every year in our country. There are a lot of people in the game is "good player”, the rest is "bad player”. Now, Xiao Ming is referee of the wrestling match and he has a list of the matches in his hand. At the same time, he knows some people are good players,some are bad players. He believes that every game is a battle between the good and the bad player. Now he wants to know whether all the people can be divided into "good player" and "bad player".

Input

Input contains multiple sets of data.For each set of data,there are four numbers in the first line:N (1 ≤ N≤ 1000)、M(1 ≤M ≤ 10000)、X,Y(X+Y≤N ),in order to show the number of players(numbered 1toN ),the number of matches,the number of known "good players" and the number of known "bad players".In the next M lines,Each line has two numbersa, b(a≠b) ,said there is a game between a and b .The next line has X different numbers.Each number is known as a "good player" number.The last line contains Y different numbers.Each number represents a known "bad player" number.Data guarantees there will not be a player number is a good player and also a bad player.

Output

If all the people can be divided into "good players" and "bad players”, output "YES", otherwise output "NO".

Sample Input

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

Sample Output

NO
YES

 并查集+dfs

https://blog.csdn.net/luricheng/article/details/53055736

 

 

D-A Simple Math Problem

 

Given two positive integers a and b,find suitable X and Y to meet the conditions:
                                                        X+Y=a
                                              Least Common Multiple (X, Y) =b

Input

Input includes multiple sets of test data.Each test data occupies one line,including two positive integers a(1≤a≤2*10^4),b(1≤b≤10^9),and their meanings are shown in the description.Contains most of the 12W test cases.

Output

For each set of input data,output a line of two integers,representing X, Y.If you cannot find such X and Y,output one line of "No Solution"(without quotation).

Sample Input

6 8
798 10780

Sample Output

No Solution
308 490

矩阵快速幂 

 

 

F-Detachment

 

In a highly developed alien society, the habitats are almost infinite dimensional space. 
In the history of this planet,there is an old puzzle. 
You have a line segment with x units’ length representing one dimension.The line segment can be split into a number of small line segments: a1,a2a1,a2, … (x= a1+a2a1+a2+…) assigned to different dimensions. And then, the multidimensional space has been established. Now there are two requirements for this space: 
1.Two different small line segments cannot be equal ( ai≠ajai≠aj when i≠j). 
2.Make this multidimensional space size s as large as possible (s= a1∗a2a1∗a2*...).Note that it allows to keep one dimension.That's to say, the number of ai can be only one. 
Now can you solve this question and find the maximum size of the space?(For the final number is too large,your answer will be modulo 10^9+7) 

Input

The first line is an integer T,meaning the number of test cases. 
Then T lines follow. Each line contains one integer x. 
1≤T≤10^6, 1≤x≤10^9

Output

Maximum s you can get modulo 10^9+7. Note that we wants to be greatest product before modulo 10^9+7.

Sample Input

1
4

Sample Output

4

逆元

 

 

 

 

 

H - To begin or not to begin 

A box contains black balls and a single red ball. Alice and Bob draw balls from this box without replacement, alternating after each draws until the red ball is drawn. The game is won by the player who happens to draw the single red ball. Bob is a gentleman and offers Alice the choice of whether she wants to start or not. Alice has a hunch that she might be better off if she starts; after all, she might succeed in the first draw. On the other hand, if her first draw yields a black ball, then Bob’s chances to draw the red ball in his first draw are increased, because then one black ball is already removed from the box. How should Alice decide in order to maximize her probability of winning? Help Alice with decision.

Input

Multiple test cases (number of test cases≤50), process till end of input. 
For each case, a positive integer k (1≤k≤10^5) is given on a single line. 

Output

For each case, output: 
1, if the player who starts drawing has an advantage 
2, if the player who starts drawing has a disadvantage 
0, if Alice's and Bob's chances are equal, no matter who starts drawing 
on a single line. 

Sample Input

1
2

Sample Output

0
1

概率论知识:

实话说,我是蒙对的。

https://blog.csdn.net/qq_34374664/article/details/53465543?locationNum=5&fps=1

https://blog.csdn.net/Jaihk662/article/details/77417091

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<math.h>
using namespace std;
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		if(n%2==0)
		{
			puts("1");
		}
		else
		{
			puts("0");
		}
	}
	return 0;
}

 

I - Convex

We have a special convex that all points have the same distance to origin point. 
As you know we can get N segments after linking the origin point and the points on the convex. We can also get N angles between each pair of the neighbor segments. 
Now give you the data about the angle, please calculate the area of the convex 

Input

There are multiple test cases. 
The first line contains two integer N and D indicating the number of the points and their distance to origin. (3 <= N <= 10, 1 <= D <= 10) 
The next lines contain N integers indicating the angles. The sum of the N numbers is always 360. 

Output

For each test case output one float numbers indicating the area of the convex. The printed values should have 3 digits after the decimal point. 

Sample Input

4 1
90 90 90 90
6 1
60 60 60 60 60 60

Sample Output

2.000
2.598

题意:给出点的个数和点到远点的距离,下面给出度数,每一个点与原点相连接都会形成一个线段,相邻两个线段之间的形成的角度就是输入数据第二行输入的数据。

让我们来求这样形成的多边形的面积。

简单来看,就是以原点为圆心,以输入的数值为半径画圆,计算这些在圆的周围的点相连接形成的多边形。

运用到高中数学中求三角形面积公式  1/2*a*b*sin(c);

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<queue> 
#include<math.h>
using namespace std;
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
	//	printf("%lf\n",sin(60/180.0*acos(-1.0)));
		double sum=0.0;
		for(int i=1;i<=n;i++)
		{
			double a;
			scanf("%lf",&a);
			sum=sum+((1.0/2.0)*m*m*sin(a/180.0*acos(-1.0)));
//在c语言中是用弧长来计算度数的,不是直接把角的度数写进去
//注意sin60度不是 sin(60) 而是 sin(60。0*PI/180.0)
//其中 PI = acos(-1.0); 
		}
		printf("%.3lf\n",sum);
	}
    return 0;
}

注意:

1.运用到数学求三角形面积公式: 1/2*a*b*sin(c);

2.数学函数中求角度的sin值,不是直接把角的度数放到sin里面,而是用公式 sin(度数/180.0*PI),其中PI也是有公式的acos(-1.0); 

J - Find Small A

 

As is known to all,the ASCII of character 'a' is 97. Now,find out how many character 'a' in a group of given numbers. Please note that the numbers here are given by 32 bits’ integers in the computer.That means,1digit represents 4 characters(one character is represented by 8 bits’ binary digits).

Input

The input contains a set of test data.The first number is one positive integer N (1≤N≤100),and then N positive integersai (1≤ aiai≤2^32 - 1) follow

Output

Output one line,including an integer representing the number of 'a' in the group of given numbers.

Sample Input

3
97 24929 100

Sample Output

3

 题意: 题目让根据输入的每一个整数,一个32位的整数,一位代表4个字符,一个字符有8位二进制数表示,

这是32位的十进制整数,转化为二进制正好是32位,每8位代表一个字符;

根据上面的描述,我们可以把输入的整数,转化位二进制,然后从后往前取8位,这8位就代表一个字符,取完之后再继续往前取,直到不能取为止。

一个十进制数,取其二进制的后八位就用%256,取完后八位剩下的数值就是  /256。

2^8=256;

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<queue> 
using namespace std;
//位运算 根据题意,我们要取每一个数字的每8位作为一个字符,所以把一个数字转化为二进制,从后往前
//取八位,如果这八位能转化为十进制的97,就是一个a,否则继续往下再取八位,直到不能再取了。 
int main()
{
	int n,m;
	while(scanf("%d",&n)!=EOF)
	{
		int sum=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d",&m);
			while(m)
			{
				if(m%256==97)//256就是2的8次方减一   
				 sum++;
				m=m/256;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值