2014 Multi-University Training Contest 1
A hdu4861
打表找规律
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define eps 1e-4
#define zero(x) ((fabs(x)<eps)?0:x)
int main()
{
int n,k;
while(~scanf("%d%d",&n,&k))
{
int x=n/(k-);
if(x%==)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return ;
}
B hdu4862
D hdu4864
把机器和任务放在一块以时间排序,因为2*100《500 时间的影响远远大于等级
优先顺序依次为:时间由大到小,等级由大到小,先机器后任务
然后遍历开数组存以yi为等级的机器还有多少个,当遍历到任务时从当前任务的等级y--100 寻找可用的机器
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 101010
#define LL __int64
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct node
{
int x,y;
int flag;
}p[N*];
int o[];
bool cmp(node a,node b)
{
if(a.x==b.x)
{
if(a.y==b.y)
return a.flag<b.flag;
return a.y>b.y;
}
return a.x>b.x;
}
int main()
{
int n,m,i,j;
int t = ;
while(scanf("%d%d",&n,&m)!=EOF)
{
// t++;
// if(t>7)
// {
// while(1);
// }
memset(o,,sizeof(o));
for(i = ; i <= n ;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
p[i].flag = ;
}
for(i = +n; i<= n+m ; i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
p[i].flag = ;
}
sort(p+,p+m+n+,cmp);
int ans = ;
LL sum = ;
for(i = ; i <= n+m; i++)
{
//cout<<p[i].x<<" "<<p[i].y<<" "<<p[i].flag<<endl;
if(p[i].flag==)
{
o[p[i].y]++;
}
else
{
for(j = p[i].y ; j<= ; j++)
{
if(!o[j]) continue;
o[j]--;
ans++;
sum+=500LL*p[i].x+*p[i].y;
break;
}
}
}
printf("%d %I64d\n",ans,sum);
}
return ;
}
E
求以给出干燥程度序列的最大概率所得的路径,首先求这样一个序列的最大概率,然后记录路径。
dp[i][j][k]表示第i天干燥程度为j天气为k dp[i][j][k] = max(dp[i][j][k],dp[i-1][c[i-1]][g]*a[g][j]*b[j][k]) c[i]表示第i天的干燥程度 ab表示题目给出的两个概率矩阵
因为数值太小,用log转乘法为加法
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
double dp[][][];
double o[];
int ps[][][];
int c[];
int ans[];
double pa[][] = {,,,,,0.5,0.375,0.125,,0.25,0.125,0.625,,0.25,0.375,0.375};
double pb[][] = {,,,,,,0.6,0.2,0.15,0.05,,0.25,0.3,0.2,0.25,,0.05,0.1,0.35,0.5};
int judge(char *s)
{
if(strcmp(s,"Dry")==) return ;
else if(strcmp(s,"Dryish")==) return ;
else if(strcmp(s,"Damp")==) return ;
return ; }
int main()
{
char s[];
int t,i,j,n;
int kk = ;
cin>>t;
while(t--)
{
cin>>n;
for(i = ; i <= n ; i++)
for(j = ;j <= ; j++)
for(int g = ; g <= ; g++)
dp[i][j][g] = -INF;
o[] = 0.63;
o[] = 0.17;
o[] = 0.2;
for(i = ; i <= n; i++)
{
scanf("%s",s);
int k = judge(s);
c[i] = k;
}
for(i = ; i <= ; i++)
{
dp[][c[]][i] = log(o[i])+log(pb[i][c[]]);
}
for(i = ; i <=n ; i++)
{
int k = c[i];
for(j = ; j <= ;j++)
{
for(int g = ; g <= ; g++)
{
double s = log(pa[g][j]);
double ts = dp[i-][c[i-]][g]+s+log(pb[j][k]);
if(dp[i][k][j]<ts)
{
dp[i][k][j] = ts;
ps[i][k][j] = g;
}
}
}
}
int x;
double maxz = -INF;
for(i = ; i <= ; i++)
{
if(maxz<dp[n][c[n]][i])
{
maxz =dp[n][c[n]][i];
ans[n] = i;
x = ps[n][c[n]][i];
}
}
int y = n;
while(y!=)
{
y--;
ans[y] = x;
x = ps[y][c[y]][x];
}
printf("Case #%d:\n",++kk);
for(i = ; i <= n ; i++)
{
if(ans[i]==)
puts("Sunny");
else if(ans[i]==)
puts("Cloudy");
else puts("Rainy");
}
}
return ;
}
H
官方解答:
最终的结果一定是连续出现的,只需要求出最终的区间。
因为如果对同一张牌进行两次操作,牌的状态不改变。故牌的翻转次数一定是减少偶数次。如果所有数的和是奇数,那么最终结果也一定是奇数。同理,偶数也是一样的。
所以只要递推求出最后的区间,计算sum(C(xi,m)(i=0,1,2。。。)),m是总牌数,xi是在区间内连续的奇数或偶数,在模10^9+9就是最终的答案。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100010
#define LL long long
#define INF 0xfffffff
#define mod 1000000009
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
int x[N];
LL pp[N];
void init()
{
int i;
pp[] = ;
for(i = ; i <= N- ; i++)
{
pp[i] = (pp[i-]*i)%mod;
}
} LL fastmod(LL a,LL k)
{
LL b = ;
while(k)
{
if(k&)
b = a*b%mod;
a = (a%mod)*(a%mod)%mod;
k/=;
}
return b;
} int main()
{
int n,m,i;
init();
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i = ;i <= n; i++)
scanf("%d",&x[i]);
int minz = ,maxz = ;
for(i = ;i <= n ; i++)
{
int tmz = minz-x[i];
int tma = maxz+x[i];
if(tmz<)
{
if(x[i]<=maxz)
tmz = abs(minz-x[i])%;
else tmz = x[i]-maxz;
}
if(tma>m)
{
if(x[i]+minz<=m)
tma = m-abs(x[i]-maxz)%;
else tma = m-(x[i]+minz-m);
}
minz = tmz;
maxz = tma;
}
LL ans = ;
for(i = minz; i <= maxz ; i+=)
{
ans = (ans+(pp[m]*fastmod((pp[i]*pp[m-i])%mod,mod-))%mod)%mod;
}
cout<<ans<<endl;
}
return ;
}
I
因为只有+50和-100,可以把1000压缩成20,容易列出dp方程i<=j时 dp[i][j] = p*dp[i+1][j]+(1-p)*dp[min(i-2,0)][j]+1;
循环一遍列出多个这样的方程,用高斯消元求解,这里需要精度高一些。
#include <iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define eps 1e-15
#define zn 403
double a[][];
double ans[];
int o[][];
void gauss(int zw,int zr)
{
int i,j,k,g = ;
for(k = ; k < zw && g < zr; k++,g++)
{
i = k;
for(j = k+ ; j <= zw ; j++)
{
if(fabs(a[j][g])>fabs(a[i][g]))
i = j;
}
if(fabs(a[i][g])<eps)
{
continue;
}
if(i!=k)
for(j = k ;j <= zr ; j++)
swap(a[i][j],a[k][j]);
for(i = k+ ; i <= zw ; i++)
{
if(fabs(a[i][k])<eps) continue;
double s = a[i][g]/a[k][g];
a[i][g] = 0.0;
for(j = g+ ; j <= zr; j++)
a[i][j] -= s*a[k][j];
}
}
for(i = zw ; i >= ; i--)
{
if(fabs(a[i][i])<eps) continue;
double s = a[i][zn];
for(j = i+ ; j <= zw ;j++)
s-=a[i][j]*ans[j];
ans[i] = s/a[i][i];
}
}
int main()
{
int i,j;
double p;
while(scanf("%lf",&p)!=EOF)
{
memset(a,,sizeof(a));
memset(ans,,sizeof(ans));
int g = ;
int e = ;
for(i = ; i < ; i++)
for(j = ; j < ; j++)
o[i][j] = ++e;
o[][] = ++e;
o[][] = ++e;
for(i = ; i < ; i++)
for(j = ; j < ; j++)
{
++g;
if(i>j)
{
a[g][o[i][j]] += 1.0;
int tj = max((j-),);
a[g][o[i][tj]] += (p-1.0);
tj = min(j+,);
a[g][o[i][tj]]-=p;
}
else
{
a[g][o[i][j]] += 1.0;
int ti = max((i-),);
a[g][o[ti][j]] += (p-1.0);
ti = min(i+,);
a[g][o[ti][j]]-=p;
}
}
for(i = ; i <= g ; i++)
a[i][e+] = ;
gauss(g,e+);
// for(i = 1; i <= 441 ; i++)
printf("%f\n",ans[]);
}
return ;
}
2014 Multi-University Training Contest 1的更多相关文章
- HDU4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)
Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- hdu 4946 2014 Multi-University Training Contest 8
Area of Mushroom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 2014 Multi-University Training Contest 9#11
2014 Multi-University Training Contest 9#11 Killing MonstersTime Limit: 2000/1000 MS (Java/Others) ...
- 2014 Multi-University Training Contest 9#6
2014 Multi-University Training Contest 9#6 Fast Matrix CalculationTime Limit: 2000/1000 MS (Java/Oth ...
- 2014 Multi-University Training Contest 1/HDU4861_Couple doubi(数论/法)
解题报告 两人轮流取球,大的人赢,,, 贴官方题解,,,反正我看不懂.,,先留着理解 关于费马小定理 关于原根 找规律找到的,,,sad,,, 非常easy找到循环节为p-1,每个循环节中有一个非零的 ...
- 2014 Multi-University Training Contest 1/HDU4864_Task(贪心)
解题报告 题意,有n个机器.m个任务. 每一个机器至多能完毕一个任务.对于每一个机器,有一个最大执行时间Ti和等级Li,对于每一个任务,也有一个执行时间Tj和等级Lj.仅仅有当Ti>=Tj且Li ...
- hdu 4937 2014 Multi-University Training Contest 7 1003
Lucky Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) T ...
- hdu 4941 2014 Multi-University Training Contest 7 1007
Magical Forest Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- hdu 4939 2014 Multi-University Training Contest 7 1005
Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- hdu 4930 Fighting the Landlords--2014 Multi-University Training Contest 6
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 Fighting the Landlords Time Limit: 2000/1000 MS ...
随机推荐
- document.createElement()的用法<> 加强我对陌生代码的理解!
document.createElement()的用法 分析代码时,发现自己的盲点——document.createElement(),冲浪一番,总结了点经验. document.createElem ...
- 关闭用miniUI打开的窗口
miniUI打开的窗口用window.close关闭无效, 应该用window.CloseOwnerWindow();
- [团队项目]SCRUM项目5.0
5.0--------------------------------------------------- 1.团队成员完成自己认领的任务. 2.燃尽图:理解.设计并画出本次Sprint的燃尽图的理 ...
- MultiSelectComboBox(二)
1. MainWindow.xaml <Window x:Class="MultiSelectDemo.MainWindow" xmlns="htt ...
- Pots 分类: 搜索 POJ 2015-08-09 18:38 3人阅读 评论(0) 收藏
Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11885 Accepted: 5025 Special Judge D ...
- 迷之节约 分类: sdutOJ 最小生成树 2015-06-24 19:10 10人阅读 评论(0) 收藏
迷之节约 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 FF超级有钱,最近又买了n个(1 <= n <= 300)小岛,为 ...
- Unity-Animator深入系列---FAQ
回到 Animator深入系列总目录 Q: 如果想做角色负伤的一套动画,但是又和原有状态机不冲突,只是想换动画剪辑,应该怎么办? A: 新建一个层,设置为同步模式.这时候你不能在同步层添加状态,但你可 ...
- HDU(2089),数位DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2089 不要62 Time Limit: 1000/1000 MS (Java/Others ...
- css公共样式,初始化
/* CSS Document */ body, button, select, textarea, input, label, option, fieldset, legend{font-famil ...
- linq的创建 和 数据的增删改查
1.linq创建之前,一定要在sql做好数据表的主外键关系. 2.linq文件是以.dbml结尾,一般一个数据库的名字就是一个linq的名字 3,以实例来演示增删改查 数据库的名字为linq,里面有两 ...