ACM-ICPC 2017 Asia Urumqi(第八场)
A. Coins
Alice and Bob are playing a simple game. They line up a row of nnn identical coins, all with the heads facing down onto the table and the tails upward.
For exactly mmm times they select any kkk of the coins and toss them into the air, replacing each of them either heads-up or heads-down with the same possibility. Their purpose is to gain as many coins heads-up as they can.
Input
The input has several test cases and the first line contains the integer t(1≤t≤1000) which is the total number of cases.
For each case, a line contains three space-separated integers n, m(1≤n,m≤100) and k(1≤k≤n.
Output
For each test case, output the expected number of coins heads-up which you could have at the end under the optimal strategy, as a real number with the precision of 3 digits.
样例输入
6
2 1 1
2 3 1
5 4 3
6 2 3
6 100 1
6 100 2
样例输出
0.500
1.250
3.479
3.000
5.500
5.000
题目来源
概率DP.
设dp[i][j]是第i次操作后正面朝上的概率,则反面朝上还有n-j枚,若n-j大于k,则k中任取
若n-j小于k,则必须从已经正面朝上的硬币中取j-(k-(n-j))枚
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
int dcmp(double x){return fabs(x)<esp?:x<?-:;}
typedef long long ll;
int n,m,k,T;
double dp[][];
double p[],c[][];
void solve()
{
c[][]=;
for(int i=;i<=;i++)
{
c[i][]=;
for(int j=;j<=;j++)
c[i][j]=c[i-][j-]+c[i-][j];
}
p[]=;
for(int i=;i<=;i++)
p[i]=p[i-]/2.0;
}
int main()
{
solve();
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
memset(dp,,sizeof(dp));
dp[][]=;
for(int i=;i<m;i++)
{
for(int j=;j<=n;j++)
{
for(int t=;t<=k;t++)
{
if(n-j>=k) dp[i+][j+t]+=dp[i][j]*c[k][t]*p[k];
else dp[i+][n-k+t]+=dp[i][j]*c[k][t]*p[k];
}
}
}
double ans=0.0;
for(int i=;i<=n;i++)
ans+=i*dp[m][i];
printf("%.3lf\n",ans);
}
return ;
}
B. The Difference
Alice was always good at math. Her only weak points were multiplication and subtraction. To help her with that, Bob presented her with the following problem.
He gave her four positive integers. Alice can change their order optionally. Her task is to find an order, denoted by A1,A2,A and A4, with the maximum value of A1×A2−A3×A4.
Input
The input contains several test cases and the first line provides an integer t(1≤t≤100) indicating the number of cases.
Each of the following t lines contains four space-separated integers.
All integers are positive and not greater than 100.
Output
For each test case, output a line with a single integer, the maximum value of A1×A2−A3×A4.
样例输入
5
1 2 3 4
2 2 2 2
7 4 3 8
100 99 98 97
100 100 1 2
样例输出
10
0
44
394
9998
签到题
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
int dcmp(double x){return fabs(x)<esp?:x<?-:;}
typedef long long ll;
int main()
{
int n,a[];
scanf("%d",&n);
while(n--){
for(int i=;i<;i++)
scanf("%d",&a[i]);
int ans=a[]*a[]-a[]*a[];
for(int i=;i<;i++)
for(int j=;j<;j++)
for(int k=;k<;k++)
if(!(i==j || j==k || i==k))
ans=max(ans,a[i]*a[j]-a[k]*a[-i-j-k]);
printf("%d\n",ans);
}
return ;
}
D. Fence Building
Farmer John owns a farm. He first builds a circle fence. Then, he will choose n points and build some straight fences connecting them. Next, he will feed a cow in each region so that cows cannot play with each other without breaking the fences. In order to feed more cows, he also wants to have as many regions as possible. However, he is busy building fences now, so he needs your help to determine what is the maximum number of cows he can feed if he chooses these n points properly.
Input
The first line contains an integer 1≤T≤100000, the number of test cases. For each test case, there is one line that contains an integer n. It is guaranteed that 1≤T≤105 and 1≤n≤1018.
Output
For each test case, you should output a line ”Case #i: ans” where i is the test caseS number, starting from 1 and ans is the remainder of the maximum number of cows farmer John can feed when divided by 109+7.
样例输入
3
1
3
5
样例输出
Case #1: 1
Case #2: 4
Case #3: 16
结论题
w=C(n,2)+C(n,4)+1;
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
int dcmp(double x){return fabs(x)<esp?:x<?-:;}
typedef long long ll;
ll n,t;
void exgcd(ll a,ll b,ll &x,ll &y)
{
ll t;
if(!b){x=;y=;return ;}
exgcd(b,a%b,x,y);
t=x;x=y;
y=t-a/b*x;
}
ll inv(ll n)
{
ll x,y;
exgcd(n,MOD,x,y);
return (x+MOD)%MOD;
}
ll C(ll n,ll m)
{
if(m>n) return ;
ll ans=;
for(ll i=;i<=m;i++)
{
ans=(ans*(n-i+)%MOD*inv(i)%MOD)%MOD;
}
return ans; }
ll solve(ll n,ll m)
{
if(m==) return ;
return C(n%MOD,m%MOD)*solve(n/MOD,m/MOD)%MOD;
}
int main()
{
scanf("%lld",&t);
ll o=t;
while(t--)
{
scanf("%lld",&n);
printf("Case #%lld: %lld\n",o-t,(solve(n,)+solve(n,)+)%MOD);
}
return ;
}
G. The Mountain
All as we know, a mountain is a large landform that stretches above the surrounding land in a limited area. If we as the tourists take a picture of a distant mountain and print it out, the image on the surface of paper will be in the shape of a particular polygon.
From mathematics angle we can describe the range of the mountain in the picture as a list of distinct points, denoted by (x1,y1) to (xn,yn). The first point is at the original point of the coordinate system and the last point is lying on the x-axis. All points else have positive y coordinates and incremental xxx coordinates. Specifically, all x coordinates satisfy 0=x1<x2<x3<...<xn. All y coordinates are positive except the first and the last points whose yyy coordinates are zeroes.
The range of the mountain is the polygon whose boundary passes through points (x1,y1) to (xn,yn) in turn and goes back to the first point. In this problem, your task is to calculate the area of the range of a mountain in the picture.
Input
The input has several test cases and the first line describes an integer t(1≤t≤20) which is the total number of cases.
In each case, the first line provides the integer n(1≤n≤100) which is the number of points used to describe the range of a mountain. Following n lines describe all points and the iii-th line contains two integers xix_ixi and yi(0≤xi,yi≤1000) indicating the coordinate of the i-th point.
Output
For each test case, output the area in a line with the precision of 666 digits.
样例输入
3
3
0 0
1 1
2 0
4
0 0
5 10
10 15
15 0
5
0 0
3 7
7 2
9 10
13 0
样例输出
1.000000
125.000000
60.500000
计算不规则多边形面积,因为x有序,y>0所以切成梯形来计算
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
int dcmp(double x){return fabs(x)<esp?:x<?-:;}
typedef long long ll;
struct Point{
double x,y;
}e[];
int n,t;
int main()
{
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%lf%lf",&e[i].x,&e[i].y);
double ans=0.0;
for(int i=;i<n;i++)
ans+=(e[i].y+e[i-].y)*(e[i].x-e[i-].x);
printf("%.6lf\n",ans/);
}
return ;
}
ACM-ICPC 2017 Asia Urumqi(第八场)的更多相关文章
- ACM ICPC 2017 Warmup Contest 9 I
I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...
- ACM ICPC 2017 Warmup Contest 9 L
L. Sticky Situation While on summer camp, you are playing a game of hide-and-seek in the forest. You ...
- ACM-ICPC 2017 Asia Urumqi A. Coins
Alice and Bob are playing a simple game. They line up a row of n identical coins, all with the heads ...
- ACM-ICPC 2017 Asia Urumqi G. The Mountain
All as we know, a mountain is a large landform that stretches above the surrounding land in a limite ...
- ACM-ICPC 2017 Asia Urumqi:A. Coins(DP) 组合数学
Alice and Bob are playing a simple game. They line up a row of nn identical coins, all with the head ...
- ACM/ICPC 之 BFS-广搜进阶-八数码(经典)(POJ1077+HDU1043)
八数码问题也称为九宫问题.(本想查查历史,结果发现居然没有词条= =,所谓的历史也就不了了之了) 在3×3的棋盘,摆有八个棋子,每个棋子上标有1至8的某一数字,不同棋子上标的数字不相同.棋盘上还有一个 ...
- ACM-ICPC 2017 Asia Urumqi:A. Coins(DP)
挺不错的概率DP,看似基础,实则很考验扎实的功底 这题很明显是个DP,为什么???找规律或者算组合数这种概率,N不可能给的这么友善... 因为DP一般都要在支持N^2操作嘛. 稍微理解一下,这DP[i ...
- ACM-ICPC 2017 Asia Urumqi A. Coins【期望dp】
题目链接:https://www.jisuanke.com/contest/2870?view=challenges 题目大意:给出n个都正面朝下的硬币,操作m次,每次都选取k枚硬币抛到空中,求操作m ...
- hdu 6143: Killer Names (2017 多校第八场 1011)
题目链接 题意,有m种颜色,给2n个位置染色,使左边n个和右边n个没有共同的颜色. 可以先递推求出恰用i种颜色染n个位置的方案数,然后枚举两边的染色数就可以了,代码很简单. #include<b ...
随机推荐
- 关于输入getline
此函数可读取整行,包括前导和嵌入的空格,并将其存储在字符串对象中. getline 函数如下所示: getline(cin, inputLine); 其中 cin 是正在读取的输入流,而 inputL ...
- WIN32常用
//1.设置窗口大小 MoveWindow(hWnd, , , + , + , FALSE); //放在InitInstance用于设置位置与窗口大小 //传递句柄就可以绘图 //2.双缓冲绘图模式 ...
- 解决Mysql报错:PHP Warning: mysql_connect(): mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication.
最近我更新了appserv-win32-2.5.10的 PHP 5.2版本到PHP 5.3,在调用http://localhost/phpMyAdmin/时,出现如下错误:PHP Warning: ...
- Node_进阶_3
Express框架: 一. Express框架 Express框架是后台的Node框架,类似于JS中的jquery. #原生Node开发会有很多问题: 1呈递静态页面很不方便,需要处理每个HTTP ...
- 集合(set)的基本操作
集合是一个无序的,不重复的数据组合,它的主要作用如下: 去重,把一个列表变成集合,就自动去重了 集合中的元素必须是不可变类型 关系测试,测试两组数据之前的交集.差集.并集等关系 常用操作 a = se ...
- IE模式下EasyUI Combobox无效问题
近期开发过程中遇到IE浏览器Combobox无法正常加载问题. 经过一番百度说IE渲染过快导致页面渲染完了easyUI Combobox还没有加载.设置延迟加载后依旧无效. 后将input标签的Cla ...
- luogu P3674 小清新人渣的本愿(莫队+bitset)
这题是莫队维护bitset. 然而我并不会bitset以前讲过认为不考就没学 我真的太菜了. 首先维护一个权值的bitset--s. 操作3比较简单,我们可以\(\sqrt{x}\)枚举约数然后判断就 ...
- c traps and pitfalls reading notes(2)
1.运算符优先级,这个我是肯定记不住,每次遇到的时候都纠结下,然后去查下,或者直接括号,但是括号太多,你懂得,要用notepad才能理清各种层次.这里啦个下来,留着参考.
- 关于Subversion主从备份方式的调整(全量、增量脚本)更新
本文引用于http://blog.chinaunix.net/uid-25266990-id-3369172.html 之前对Subversion服务器作了迁移,关于SVN的架构也走了调整,有单一的服 ...
- 关于iptables允许samba的问题
今天同事跟我说他们部门的共享不能用了,想了想,最近变更的只有iptables,于是看看是否是这个原因,发现没有允许samba的入站和出站规则,我的iptables规则默认是所有都drop的,但是不知确 ...