BestCoder 2nd Anniversary
A题 Oracle
http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=703&pid=1001
大数相加:
rec[p]=;
rec[]+=k;
;i<p;i++)
) rec[i] = rec[i] - ,rec[i+] ++ ;
)
printf("%d",rec[p]);
#include <cstdio>
#include <cstring>
;
int rec[maxn];
];
int main()
{
int T;
scanf("%d",&T);
getchar();
while(T--)
{
memset(num,,sizeof(num));
char ch=getchar();
;//记录非零数的数量
')
{
') cnt++;
num[ ch-' ]++;
ch=getchar();
}
)
{
printf("Uncertain\n");continue;
}
;
while (!num[k])
k++;
num[k]--;
;
;i<=;i++)
{
while(num[i])
{
rec[p++] = i;
num[i]--;
}
}
rec[p]=;
rec[]+=k;
;i<p;i++)
) rec[i] = rec[i] - ,rec[i+] ++ ;
)
printf("%d",rec[p]);
;i>=;i--)
putchar('+rec[i]);
puts("");
}
;
}
B题 Arrange
http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=703&pid=1002
根据B和C数组的改变,可以推测出A数组中原序列的值。
①B数组不变,C数组变大,A[i] = C[i],可供挑选数字,增加 C[i] - C[i-1] - 1 个。
②C数组不变,B数组变小,A[i] = B[i],可供挑选数字,增加 B[i-1] - B[i] - 1 个。
③B,C数据均不变,计算一下可能的种类数
④其余情况,均说明不存在合法序列
#include <cstdio>
+ ;
;
int B[maxn],C[maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
;i < n;i++)
scanf("%d",&B[i]);
;i < n;i++)
scanf("%d",&C[i]);
;
] != C[]) flag = ;
;//remain
;
;i < n;i++)
{
] && C[i] == C[i-])
{
) {flag = ;break;}
else {ans = ans * rem % mod; rem--;}
}
] && C[i] > C[i-]){rem = rem + C[i] - C[i-] - ;}
] && C[i] == C[i-]){rem = rem + B[i-] - B[i] - ;}
;break;}
}
) {printf("0\n");continue;}
printf("%I64d\n",ans);
}
;
}
C题Wool
http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=703&pid=1003
假设我们需要加入的边为c,若abc构成一个三角形,若要使c的可选择范围最小,那么即 a-b 到 a+b的范围最大(假设a>=b)
可以通过数学,发现,显然当a确定的时候,b越大,这个范围越大,所以我们对a数组进行排序后,记录相邻两个ai的a-b和a+b。
再对结点node进行排序之后,这道题的核心代码部分
ll rem=,cur_ri=L-;//longlong写成int
;i<=n;i++)
{
)
{
ll l1 = cur_ri + ;
ll r1 = node[i].left - ;
if(l1 > R || r1 < L) continue;
rem = rem + min(R,r1) - max(L,l1) + ;
}
if(cur_ri < node[i].right) cur_ri = node[i].right;
}
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
+ ;
typedef long long ll;
int n;
ll L,R;
ll a[maxn];
struct Node
{
ll left,right;
}node[maxn];
bool cmp(const Node&a,const Node&b)
{
return a.left<b.left || ( (a.left == b.left) && (a.right < b.right) );
}
int main()
{
int T;
cin>>T;
while(T--)
{
cin>>n>>L>>R;
;i<n;i++)
cin>>a[i];
sort(a,a+n);
;i<n;i++)
{
node[i].left=a[i]-a[i-]+;
node[i].right=a[i]+a[i-]-;
}
node[n].left = 2e18;
sort(node+,node++n,cmp);
ll rem=,cur_ri=L-;
;i<=n;i++)
{
)
{
ll l1 = cur_ri + ;
ll r1 = node[i].left - ;
if(l1 > R || r1 < L) continue;
rem = rem + min(R,r1) - max(L,l1) + ;
}
if(cur_ri < node[i].right) cur_ri = node[i].right;
}
cout<<rem<<endl;
}
;
BestCoder 2nd Anniversary的更多相关文章
- BestCoder 2nd Anniversary的前两题
Oracle Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Su ...
- hdu 5719 BestCoder 2nd Anniversary B Arrange 简单计数问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5719 题意:一个数列为1~N的排列,给定mn[1...n]和mx[1...n],问有符合的排列数为多少 ...
- hdu 5720 BestCoder 2nd Anniversary Wool 推理+一维区间的并
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5720 题意:有n(n <= 105)个数 ,每个数小于等于 1018:问在给定的[L,R]区间中 ...
- BestCoder 2nd Anniversary 1001 Oracle
找到最小的非零数字拆开来相加. 高精度. #include <iostream> #include <cstdio> #include <cstring> #inc ...
- BestCoder 2nd Anniversary 1002 Arrange
排除所有不符合条件后根据当前位置上下界计算, 由于前面取的数肯定在之后的区间内,所以去掉已取的个数即可. #include <iostream> #include <cstdio&g ...
- BestCoder 2nd Anniversary/HDU 5719 姿势
Arrange Accepts: 221 Submissions: 1401 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/2 ...
- BestCoder 2nd Anniversary/HDU 5718 高精度 模拟
Oracle Accepts: 599 Submissions: 2576 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/26 ...
- 二分图点染色 BestCoder 1st Anniversary($) 1004 Bipartite Graph
题目传送门 /* 二分图点染色:这题就是将点分成两个集合就可以了,点染色用dfs做, 剩下的点放到点少的集合里去 官方解答:首先二分图可以分成两类点X和Y, 完全二分图的边数就是|X|*|Y|.我们的 ...
- BestCoder 1st Anniversary($) 1003 Sequence
题目传送门 /* 官方题解: 这个题看上去是一个贪心, 但是这个贪心显然是错的. 事实上这道题目很简单, 先判断1个是否可以, 然后判断2个是否可以. 之后找到最小的k(k>2), 使得(m-k ...
随机推荐
- '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp error
'0000-00-00 00:00:00' can not be represented as java.sql.Timestamp error 异常现象 ### Cause: java.sql.SQ ...
- Two-Pointer 之 Run Length Coding (RLC)
游程编码(Run Length Coding, RLC)是串处理中常见的预处理方法.其写法是典型的双指针(Two-Pointer).下面总结其写法1.输入为一串整数可以不把整数存在数组里
- Structure Of Management Information - SNMP Tutorial
30.6 The Structure Of Management Information In addition to the standards that specify MIB variables ...
- Level Of Management Protocols - SNMP Tutorial
30.2 The Level Of Management Protocols Originally, many wide area networks included management proto ...
- JavaScript中ActiveXObject对象
JavaScript中ActiveXObject对象是启用并返回 Automation 对象的引用.使用方法: newObj = new ActiveXObject( servername.typen ...
- 如何学好JAVA编程
我的思路: 1.我觉得先学学JSP,用纯JSP做个日记本简单的小系统,纯粹从语言层面上了解一些基 础知识,把tomcat玩熟了,就用记事本编就行,主要是熟悉,能够理解jsp运行机制.然 ...
- [Unity3D]添加音效说明
添加音效组件并添加音乐资源 其中Pitch用来提高和降低音调的,比如可以和赛车游戏的轮胎绑定,当轮胎越快,则音调越高 2D/3D音效:2D音效和摄影家的距离无关,可以看做是一个背景音乐:而3D音效则是 ...
- Java多线程编程核心技术---学习分享
继承Thread类实现多线程 public class MyThread extends Thread { @Override public void run() { super.run(); Sys ...
- System.Properties和System.getenv区别
网上很多使用的是getProperties.说获得系统变量,但是其实不正确.getProperties中所谓的"system properties"其实是指"java s ...
- ThinkPHP中疑难笔记
不但要记住核心的东西, 还要记住 相关的 东西: 如php cli的版本是 5.6.14 bulit: sep 30, 2015 tp中, 通常说的系统就是框架; 项目就是 "应用程序&qu ...