2016 ACM/ICPC亚洲区大连站-重现赛 解题报告
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5979
按AC顺序:
I - Convex
Time limit 1000 ms
Memory limit 65536 kB
OS Windows
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
InputThere 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.
OutputFor 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
题意概括:
给出 N 个点到中心的的距离 R 和 相邻两线的角度 a(角度和一定为360),求这个多边形面积。
解题思路:
签到题
三角形面积公式 S = 1/2 * R * R * sin( a );三角形面积和即多边形面积。
不过注意要把题目给的角度做一下转换再丢进 sin 里 a = a / pi*180,考虑精度问题,一般 pi 都通过反三角函数 acos( -1 ) 求得;
AC code:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#define LL long long
using namespace std;
const float pi = acos(-); int main()
{
double sum, r;
int N;
double arr;
int s[];
while(~scanf("%d%lf", &N, &r)){
sum = ;
for(int i = ; i < N; i++){
scanf("%lf", &arr);
//printf("%lf\n", sin(arr*pi/180));
sum += (1.00/2.00)*r*r*sin(arr*pi/);
}
//sum = pi*r*r;
printf("%.3f\n", sum);
}
return ;
}
I - Convex
H - To begin or not to begin
Time limit 1000 ms
Memory limit 65536 kB
OS Windows
InputMultiple 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.
OutputFor 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
题意概括:
签到题。
两个人从一个有 K 个黑球一个红球的盒子里取球,谁先取到红球谁胜。
每次输入 K ,判断是先取优势大(输出1)还是后取优势大(输出2),还是先取后取优势相同(输出0)。
球取出后不能放入箱子。
解题思路:
首先我们可以判断得是 后取优势大得可能性为 0,即不存在(因为无论如何后取取胜得前提都是前一个没有选中)
一开始大胆地猜测 0 的情况只有 当 K 为 1 一种,其余都是 先取有利(果断无辜WA了一发)还是要老老实实推。
然后我们模拟几次会发现 1 和 0 与 K 的奇偶性有关:
n是奇数时,先取后取的机会一样。输出0。
AC code:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std ;
int main( )
{
int N_num;
while(scanf("%d",&N_num)!=EOF)
{
if(N_num%!=)
puts("");
else
puts("");
}
return ;
}
H - To begin or not to begin
J - Find Small A
InputThe 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) followOutputOutput 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
题意概括:
签到题。
给 N 个数,每个数可化为32位二进制,问这些数包含多少个 a (ASCII 97)。
解题思路:
签到题。
模拟,一开始考虑了所有八位的情况(高估这道题目了),WA。
其实就是 X>>=8 地遍历一遍每个数就 OK 了。
AC code:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
using namespace std ;
#define D 256
#define Y 97
int FA(int x)
{
int now=;
for(int i= ; i< ; i++)
{
if(x%D==Y)
now++;
x>>=;
if(x==)
break;
}
return now;
}
int main( )
{
int n;
while(scanf("%d",&n)!=EOF)
{
int sum=;
for(int i= ; i<n ; i++)
{
int a;
scanf("%d",&a);
sum+=FA(a);
}
printf("%d\n",sum); }
}
/*
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define LL long long
using namespace std; int main()
{
int N;
while(~scanf("%d", &N)){
int ans = 0, t1, t2;
for(int i = 0; i < N; i++){
scanf("%d", &t1);
// t2 = t1;
// printf("t22:%d\n", t2);
while(t1){
if(t1%256 == 97) ans++;
t1>>=8;
// printf("t1: %d\n", t1);
// t2/=256;
// printf("t2: %d\n", t2);
}
}
printf("%d\n", ans);
}
return 0;
}
*/
J - Find Small A
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
InputInput 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.OutputFor 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
题意概括:
“一道简单的数学问题”
给出 a b两个正整数,求解 X Y;
X Y满足:
①X+Y = a
②X Y 的最小公倍数等于 b
解题思路:
我们知道如果满足X Y 的最小公倍数等于 b
那么 X*Y = GCD(X,Y)* b;
即 X*(a-X) = GCD( X, a-X) * b;
开始的做法,暴力 X (X范围到 a),果断TL;
不过通过这个暴力发现蜜汁规律:
如果X Y是满足条件的 那么 GCD(X, Y) = GCD(a, b);
最后建东哥徒手解方程,O(1)解决这道简单的数学题。
AC code:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath> using namespace std;
typedef long long LL;
LL gcd(LL a,LL b)
{
if(b==) return a;
else return gcd(b,a%b);
} int main()
{
LL a,b; while(~scanf("%lld%lld",&a,&b))
{
LL t=gcd(a,b); LL x=(a-sqrt(a*a-*t*b))/;
LL y=a-x;
// printf("x=%lld,y=%lld\n",x,y);
if(x*y==gcd(x,y)*b)
printf("%lld %lld\n",x,a-x);
else printf("No Solution\n");
}
}
D - A Simple Math Problem
A - Wrestling Match
InputInput 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.OutputIf 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
题意概括:
有 N 个人 M 个对立关系 , 已知 X 个人是好人(无重复), Y 个人是坏人(无重复),题目问是否能区分所有人的好坏。
解题思路:
各种奇思妙想,最后得出结论 DFS 或者 BFS 解决
对题目给出得对立关系建图,通过从一个结点(优先从有标记为好或者坏的)开始DFS或者BFS,记录奇偶性判断当前结点是好是坏。
如果有矛盾输出NO 否则YES。
AC code:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; typedef struct Edge {
int to, next;
}Edge; const int maxn = ;
int n, m, x, y;
int know[maxn], vis[maxn], VAL[maxn];
int cnt, head[maxn];
Edge e[maxn*maxn]; void init() {
cnt = ;
memset(head, -, sizeof(head));
memset(know, , sizeof(know));
memset(vis, , sizeof(vis));
memset(VAL, , sizeof(VAL));
} void adde(int u, int v) {
e[cnt].to = v, e[cnt].next = head[u]; head[u] = cnt++; }
int FA(int x)
{
return -x;
}
bool dfs(int u) {
for(int i = head[u]; ~i; i=e[i].next) {
int v = e[i].to;
if(VAL[v] == VAL[u]) return ;
if(vis[v]) continue;
vis[v] = ;
VAL[v] = FA(VAL[u]);
if(!dfs(v)) return ;
}
return ;
} int main() {
// freopen("in", "r", stdin);
int u, v;
while(~scanf("%d%d%d%d",&n,&m,&x,&y)) {
init();
for(int i = ; i < m; i++) {
scanf("%d%d",&u,&v);
adde(u, v); adde(v, u);
know[u] = know[v] = ;
}
for(int i = ; i < x; i++) {
scanf("%d", &u);
VAL[u] = ; know[u] = ;
}
for(int i = ; i < y; i++) {
scanf("%d", &u);
VAL[u] = ; know[u] = ;
}
bool flag = ;
for(int i = ; i <= n; i++) {
if(!know[i]) {
flag = ;
break;
}
}
if(flag) {
puts("NO");
continue;
}
for(int i = ; i <= n; i++) {
if(VAL[i]) {
vis[i] = ;
if(!dfs(i)) {
flag = ;
break;
}
}
}
for(int i = ; i <= n; i++) {
if(!VAL[i]) {
vis[i] = ;
VAL[i] = ;
if(!dfs(i)) {
flag = ;
break;
}
}
}
for(int i = ; i <= n; i++) {
if(!VAL[i]) {
vis[i] = ;
VAL[i] = ;
if(!dfs(i)) {
flag = ;
break;
}
}
}
if(!flag) puts("YES");
else puts("NO");
}
return ;
}
A - Wrestling Match
几组数据:
YES NO YES NO NO NO YES YES NO NO NO NO NO !!! NO YES
text
F - Detachment
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)
InputThe 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^9OutputMaximum 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
题意概括:
给一个数 N ,可以把它分解成若干个不相同的数 N = a1+a2+a3+...... ,求最大的 S = a1*a2*a3*.......
分多少个随意,也可以不分。
解题思路:
一开始以为是规律题,
后来推了无果,笔纸模拟到 11 发现一个神奇的贪心
要是乘积最大化,那可分的数越多越好。
而每一个数可分的数字数量是有规律的。
x1 = 1, s1 = 1;
x2 = 2, s2 = 2;
x3 = 3, s3 = 3;
x4 = 4, s4 = 4;
x5 = 2+3, s5 = 2*3;
x6 = 2+4 [2+(3+1)], s6 = 2*4;
x7 = 3+4 [(2+1) + (3+1)], s7 = 3*4;
x8 = 3+5 [(2+1) + (3+1+1)], s8 = 3*5;
x9 = 2+3+4, s9 = 2*3*4;
x10 = 2+3+5 [2+3+(4+1)], s10 = 2*3*5;
x11 = 2+4+5 [2+(3+1)+(4+1)], s11 = 2*4*5;
...
如何构造贪心显而易见了,参考一篇大牛的证明:
https://blog.csdn.net/qq_34374664/article/details/53466435
此题关键在于得出如何能使乘积s最大
按照以往经验,必然是取一段连续自然数能够使得乘积最大,而这段连续自然数可从2开始(为啥不从1开始?从1开始还不如将这个1给这段连续自然数的最后一个数),
于是我们可以得到形如2+3+4+...+k(k=2,3,...)的式子,而x是10^9内的任意整数,我们不可能恰好能够凑成连续自然数之和,可能会多出△x
而这个△x的值,我可以保证它的范围为0≤△x≤k,相信大于等于0还是好理解的,为什么会小于等于k呢?因为当它大于k时,原式不是可以增加一项?即2+3+4+...+k+(k+1)
那么多出来的△x怎么处理呢?显然是从后往前均摊给连续自然数中的(k-1)个数,为啥从后往前?因为若我们从前往后,总是会使连续自然数重复,不好处理
于是,在我们分配完△x之后,我们大致会得到下述两种式子:
①2*3*...*(i-1)*(i+1)*...*k*(k+1)
②3*4*...*i*(i+1)*...*k*(k+2)
显然,我们要计算此结果,可以借助阶乘,而阶乘中缺失的项,我们除掉就可以了,那么便会涉及除法取模,显然需要用到乘法逆元
做法讲解完毕,以下是为什么连续段乘积最大的大概证明:
简而言之,假如有一个数让你拆成两个要求积最大,肯定是拆成两个一样的,如果拆成n个,肯定就是拆成这个数/n,如果没说几个,肯定都拆成几个3就拆成几个三,剩下的拆成2.这个题要求不能一样的,所以肯定就是2,3,4这样排列了,从2开始让它变小,这样数量会最多,每次加一就是让他越来越接近。所以用前缀和记录,如果有剩余的话,肯定是从后往前逐个+1,而且剩余的那个数最多=2,3,4...最大的那个数,举个例子会发现有两种情况:1.比如2*3*4*5余下5,相等。最优就是3*4*5*7,就是每个数都加一遍,然后会剩下一个1,加给最后一个,总的来说就是 除以2,乘上t+2,(t是最后一个数的值);2.不相等,2,3,4,5,余2,最优就是2,3,5,6,就是用3的阶乘*6的阶乘除以4的阶乘,因为数量太多,不能一个一个乘,就用前缀积相除,数字太大,就要用逆元了。。然后用二分优化下。。
这题找到贪心策略后,要知道数据量大的话要用前缀积+逆元求,用前缀和优化找余数。。二分也是优化这个的
AC code:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define LL long long
using namespace std;
const int MAXN = 1e5+;
const int Mod = 1e9+; LL mul[MAXN], sum[MAXN];
void init()
{
mul[] = ;
sum[] = ;
for(int i = ; i < MAXN; i++){
sum[i] = sum[i-] + i; //前缀和
mul[i] = (i*mul[i-])%Mod; //前缀积
}
} LL inv(LL a, int b) //费马小定理求逆元
{
LL ans = ;
while(b){
if(b&) ans = (ans*a)%Mod;
a = (a*a)%Mod;
b >>= ;
}
return ans;
} int main()
{
int t, x;
init();
scanf("%d", &t);
while(t--){
scanf("%d", &x);
if(x == ){
puts("");
continue;
}
int l = , r = MAXN, mid, p;
while(l <= r){
mid = (l+r)/;
if(sum[mid] <= x) p = mid, l = mid+;
else r = mid-;
}
// printf("%d\n", p);
int num = x - sum[p];
LL ans = ;
if(num == p)
ans = (mul[p]*inv(, Mod-)%Mod*(p+))%Mod;
else
ans = (mul[p+]*inv(mul[p+-num], Mod-)%Mod*mul[p-num])%Mod;
printf("%lld\n", ans);
}
return ;
}
F - Detachment
总结:还是太年轻,任重而道远。
2016 ACM/ICPC亚洲区大连站-重现赛 解题报告的更多相关文章
- 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)
摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...
- 2016ACM/ICPC亚洲区大连站现场赛题解报告(转)
http://blog.csdn.net/queuelovestack/article/details/53055418 下午重现了一下大连赛区的比赛,感觉有点神奇,重现时居然改了现场赛的数据范围,原 ...
- 2016ACM/ICPC亚洲区大连站-重现赛
题目链接:http://acm.hdu.edu.cn/search.php?field=problem&key=2016ACM%2FICPC%D1%C7%D6%DE%C7%F8%B4%F3%C ...
- 2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)(7/10)
1001题意:n个人,给m对敌对关系,X个好人,Y个坏人.现在问你是否每个人都是要么是好人,要么是坏人. 先看看与X,Y个人有联通的人是否有矛盾,没有矛盾的话咋就继续遍历那些不确定的人关系,随便取一个 ...
- 2016 ACM/ICPC亚洲区大连站 F - Detachment 【维护前缀积、前缀和、二分搜索优化】
F - Detachment In a highly developed alien society, the habitats are almost infinite dimensional spa ...
- HDU 6227.Rabbits-规律 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))
Rabbits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- HDU 6225.Little Boxes-大数加法 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))
整理代码... Little Boxes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/O ...
- 2016ACM/ICPC亚洲区沈阳站-重现赛赛题
今天做的沈阳站重现赛,自己还是太水,只做出两道签到题,另外两道看懂题意了,但是也没能做出来. 1. Thickest Burger Time Limit: 2000/1000 MS (Java/Oth ...
- 2017ACM/ICPC亚洲区沈阳站-重现赛
HDU 6222 Heron and His Triangle 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6222 思路: 打表找规律+大数运算 首先我 ...
随机推荐
- python 爬虫系列08-同步斗图一波
一波大图来袭 import requests from lxml import etree from urllib import request import os import re def par ...
- Coursera 机器学习 第9章(下) Recommender Systems 学习笔记
9.5 Predicting Movie Ratings9.5.1 Problem Formulation推荐系统.推荐系统的问题表述:电影推荐.根据用户对已看过电影的打分来推测用户对其未打分的电影将 ...
- fabric省略输出
fab -f test_fabric.py start --hide status,running,stdout,user,aborts,warnings,stderr 省略所有输出--hide st ...
- 深入理解JavaScript系列(12):变量对象(Variable Object)
介绍 JavaScript编程的时候总避免不了声明函数和变量,以成功构建我们的系统,但是解释器是如何并且在什么地方去查找这些函数和变量呢?我们引用这些对象的时候究竟发生了什么? 原始发布:Dmitry ...
- JavaScript实现StringBuffer
function StringBuffer() { this._strings = new Array(); } StringBuffer.prototype.Append = function(_s ...
- WPF MVVM 如何在ViewModel中操作View中的控件事件
(在学习Wpf的时候,做一个小例子,想在TextBox改变后,检验合法性,并弹出提示.在找了很多贴后,发现这个小例子,抄袭过来,仅供参考. 最后也找到了适合自己例子的办法:在出发TextChanged ...
- String常用操作
常量池: 字符串一旦被初始化就不会被改变 String s="123"; s="abc"; System.out.print(s); 这段代码看上去s的值是被改 ...
- PHP file_put_contents() 函数
file_put_contents() 函数把一个字符串写入文件中. 与依次调用 fopen(),fwrite() 以及 fclose() 功能一样. 语法如下 file_put_contents(f ...
- form中button特殊功能
描述:写弹窗的时候发现,form中的button,不对它进行什么设置,它会有默认的操作,点击“发送验证码”或者“提交申请”,它都会退出弹窗(取消遮罩层) 解决:button有不同的type属性,只需要 ...
- linux环境下安装jdk(本文示例是jdk1.6.0_45)
第一步:创建一个文件夹安装jdk(虽说地址一般自定义,但是为了方便查找请按照笔者建议目录 ):/usr/java 将jdk-6u45-linux-x64.bin文件放到 /usr/java 文件夹 ...