2016 round A

A. Googol String

small && large

LL a[];
int dfs(LL pos, int id, bool f)
{
if(pos== || pos==a[id-]+)
return f? :;
if(pos>a[id-])
return dfs(a[id]-pos+, id-, f^);
else
return dfs(pos, id-, f);
}
int main()
{
freopen("A-small-practice.in", "r", stdin);
freopen("A.out", "w", stdout);
a[]=;
for(int i=;i<=;i++)
a[i]=a[i-]*+;
int t, ca=;
scanf("%d", &t);
while(t--)
{
LL n;
scanf("%I64d", &n);
int pos=lower_bound(a, a+, n)-a;
printf("Case #%d: %d\n", ca++, dfs(n, pos, ));
}
return ;
}

B. gCube

n个数,m个询问

每个询问给[l, r]

求 $\sqrt[^{r-l+1}]{\prod\limits_{i=l}^{r}a_i}$

smal

暴力二分,large TLE了 跑10min都没跑完,应该是大数乘太费时间

public class Main
{
static BigDecimal quick(BigDecimal a, BigInteger b)
{
BigDecimal ans=BigDecimal.ONE;
while(b.compareTo(BigInteger.ZERO)!=0)
{
if(b.mod(BigInteger.valueOf(2)).compareTo(BigInteger.ZERO)!=0)
ans=ans.multiply(a);
b=b.divide(BigInteger.valueOf(2));
a=a.multiply(a);
}
return ans;
}
static BigDecimal sqrt(BigDecimal x, int n)
{
BigDecimal l=BigDecimal.ZERO, r=x;
while(r.subtract(l).abs().compareTo(BigDecimal.valueOf(1e-10))>0)
{
BigDecimal m=(l.add(r)).divide(BigDecimal.valueOf(2));
BigDecimal cur=quick(m, BigInteger.valueOf(n));
cur=cur.subtract(x);
if(cur.abs().compareTo(BigDecimal.valueOf(1e-10))<0)
return m;
else if(cur.compareTo(BigDecimal.ZERO)<0)
l=m;
else
r=m;
}
return l;
}
public static void main(String[] args) throws FileNotFoundException
{
// InputReader in=new InputReader();
// PrintWriter out=new PrintWriter(System.out);
Scanner in=new Scanner(new File("B-large-practice.in"));
PrintWriter out = new PrintWriter(new File("B.out"));
int t=in.nextInt();
int ca=1;
while((t--)!=0)
{
int n=in.nextInt();
int m=in.nextInt();
int []a=new int[n];
for(int i=0;i<n;i++)
a[i]=in.nextInt();
BigDecimal []b=new BigDecimal[n];
b[0]=BigDecimal.valueOf(a[0]);
for(int i=1;i<n;i++)
b[i]=b[i-1].multiply(BigDecimal.valueOf(a[i]));
out.println("Case #"+ca+":");ca++;
while((m--)!=0)
{
int l=in.nextInt();
int r=in.nextInt();
BigDecimal pre=BigDecimal.ONE;
if(l!=0) pre=b[l-1];
BigDecimal s=b[r].divide(pre);
out.printf("%.9f", sqrt(s, r-l+1));
out.println("");
}
}
out.close();
}
}

large

求n次根号下的就是把ans除n次刚好除完

那就for l 到 r 每次都除一个ans 最后与1比较 判断是否除完就行了

const LD eps=1e-10; // eps<1e9了要long double!!!

int a[1005];
LD sqrtn(int x, int y)
{
LD l=1, r=a[y];
for(int i=x;i<=y;i++) // 数列不递增!!注意取最大值!
r=max(r, (LD)a[i]);
while(fabs(l-r)>eps)
{
LD mid=(l+r)/2.0;
LD cur=1.0;
for(int i=x;i<=y;i++)
cur*=a[i]/mid;
    // 要注意这里不能fabs(cur-1)<eps了就结束 因为cur与1<eps了 不代表mid与ans的误差也小于eps了!!
if(cur>1)
l=mid;
else
r=mid;
}
return l;
}
int main()
{
freopen("B-large-practice.in", "r", stdin);
freopen("B.out", "w", stdout);
int t, ca=1;
scanf("%d", &t);
while(t--)
{
int n, m;
scanf("%d%d", &n, &m);
for(int i=0;i<n;i++)
scanf("%d", &a[i]);
printf("Case #%d:\n", ca++);
while(m--)
{
int l, r;
scanf("%d%d", &l, &r);
printf("%.9Lf\n", sqrtn(l, r));
}
}
return 0;
}

2017 round A

A. Country Leader

给n个字符串 输出其中字母最多的字符串 字母一样多 输出字典序最小

神tm 空格only appear in Large!! 挂了A large真是日了狗的心情

 char s[];
bool vis[];
int main()
{
freopen("A-large-practice.in", "r", stdin);
freopen("A.out", "w", stdout);
int t, ca=;
scanf("%d", &t);
while(t--)
{
printf("Case #%d: ", ca++);
int n;
scanf("%d", &n);
getchar();
string ans="";
int maxn=;
for(int i=;i<n;i++)
{
gets(s);
string ss=s;
memset(vis, , sizeof(vis));
int num=;
int len=strlen(s);
for(int j=;j<len;j++)
if(s[j]!=' ' && !vis[s[j]])
num++, vis[s[j]]=;
if(num>maxn)
maxn=num, ans=s;
else if(num==maxn)
if(ss<ans)
ans=ss;
}
cout<<ans<<endl;
}
return ;
}

A

B. Rain

给n*m的方格,每个格子有高度,水满了会增加格子高度,输出增加的高度

每个格子会变成 上下左右 比它高的 最小高度

从最小的高度开始 看每格能否合法的变成这个高度

 vector<int> v;
int mp[][];
bool vis[][];
int ans, n, m;
bool can(int x, int y, int val)
{
// int num=0;
if(!vis[x][y] && mp[x][y]==val)
{
if(x== || x==n- || y== || y==m-)
return false;
vis[x][y]=;
// num=1;
if(x>){
if(!can(x-, y, val)) return false;}
if(x<n-){
if(!can(x+, y, val)) return false;}
if(y>){
if(!can(x, y-, val)) return false;}
if(y<m-){
if(!can(x, y+, val)) return false;}
}
else if(mp[x][y]<val)
return false;
return true;
}
void dfs(int x, int y, int num)
{
for(int i=;i<n;i++)
for(int j=;j<m;j++)
if(vis[i][j])
ans+=num-mp[i][j], mp[i][j]=num, vis[i][j]=;
}
int main()
{
freopen("B-large.in", "r", stdin);
freopen("B.out", "w", stdout);
int t, ca=;
scanf("%d", &t);
while(t--)
{
printf("Case #%d: ", ca++);
scanf("%d%d", &n, &m);
v.clear();
for(int i=;i<n;i++)
for(int j=;j<m;j++)
scanf("%d", &mp[i][j]), v.push_back(mp[i][j]);
sort(v.begin(), v.end());
int d=unique(v.begin(), v.end())-v.begin();
if(d<)
{
puts("");
continue;
}
ans=;
for(int ii=;ii<d;ii++)
{
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
memset(vis, , sizeof(vis));
if(mp[i][j]<v[ii] && can(i, j, mp[i][j]))
{
dfs(i, j, v[ii]);
}
}
}
}
// for(int i=0;i<n;i++){
// for(int j=0;j<m;j++)
// printf("%d ", mp[i][j]);puts("");}
printf("%d\n", ans);
}
return ;
}

B

C. Jane's Flower Shop

给n个系数 求一元n次方程在-1到1之间的那个解,题目保证有且仅有一解

因为保证有且仅有一解,因此Left和Right两端一定为一正一负

根据正负二分就行

 typedef long double LD;
const LD eps=1e-; int a[];
int n;
LD cal(LD r)
{
LD cur=, ans=;
for(int i=;i<=n;i++, cur*=(+r))
ans+=a[n-i]*cur;
return ans;
}
int main()
{
freopen("C-large.in", "r", stdin);
freopen("C.out", "w", stdout);
int t, ca=;
scanf("%d", &t);
while(t--)
{
printf("Case #%d: ", ca++);
scanf("%d", &n);
for(int i=;i<=n;i++)
scanf("%d", &a[i]);
a[]=-a[];
LD l=-, r=;
LD ll=cal(l), rr=cal(r);
while(fabs(l-r)>eps)
{
LD m=(r+l)*0.5;
LD mm=cal(m);
if(mm< && ll<)
l=m;
else if(mm< && rr<)
r=m;
else if(mm> && ll>)
l=m;
else if(mm> && rr>)
r=m;
else
l=m;
}
printf("%.12Lf\n", l);
}
return ;
}

C

APAC Practice的更多相关文章

  1. Pramp mock interview (4th practice): Matrix Spiral Print

    March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...

  2. Atitit 数据存储视图的最佳实际best practice attilax总结

    Atitit 数据存储视图的最佳实际best practice attilax总结 1.1. 视图优点:可读性的提升1 1.2. 结论  本着可读性优先于性能的原则,面向人类编程优先于面向机器编程,应 ...

  3. The Practice of .NET Cross-Platforms

    0x01 Preface This post is mainly to share the technologies on my practice about the .NET Cross-Platf ...

  4. Exercise 24: More Practice

    puts "Let's practice everything." puts 'You\'d need to know \'bout escapes with \\ that do ...

  5. ConCurrent in Practice小记 (3)

    ConCurrent in Practice小记 (3) 高级同步技巧 Semaphore Semaphore信号量,据说是Dijkstra大神发明的.内部维护一个许可集(Permits Set),用 ...

  6. ConCurrent in Practice小记 (2)

    Java-ConCurrent2.html :first-child{margin-top:0!important}img.plugin{box-shadow:0 1px 3px rgba(0,0,0 ...

  7. ConCurrent in Practice小记 (1)

    ConCurrent in Practice小记 (1) 杂记,随书自己写的笔记: 综述问题 1.线程允许在同一个进程中的资源,包括共享内存,内存句柄,文件句柄.但是每个进程有自己的程序计数器,栈和局 ...

  8. 1.2 基础知识——关于猪皮(GP,Generic Practice)

    摘要: 这是<CMMI快乐之旅>系列文章之一.说起猪皮(GP,Generic Practice),真的让人又爱又恨,中文翻译叫通用实践.CMMI标准中每个级别包含几个PA,每个PA又包含几 ...

  9. 2015年第2本(英文第1本):《The Practice of Programming》

    2015年计划透析10本英文原著,最开始选定的第一本英文书是<Who Moved my Cheese>,可是这本书实在是太短.太简单了,总体的意思就是要顺应变化,要跳出自己的舒适区,全文不 ...

随机推荐

  1. 腾讯云 安全组配置及与MySQL 远程登录失败原因浅析

    前言,知道自己腾讯云服务器安全组配置并在安全组里开放了所有端口的用户可以粗略的看看下边的内容,否则就仔细看看吧. 因为有学习及业务需要,我要在腾讯云上安装了CentOS7.2版本的服务器上安装MySQ ...

  2. 【原】WinForm中的DataGridView加入Combbox或者DropDownButton后,操作变慢

    DataGridView里加入了DropDownButto列,加载数据后点击这一列,反应很慢;要点击三到四次才会展示下拉列表; 原因是DataGridView的EditMode设置问题; 将DataG ...

  3. 节点属性(DOM对象)

    节点属性 在文档对象模型 (DOM) 中,每个节点都是一个对象.DOM 节点有三个重要的属性 : 1. nodeName : 节点的名称 2. nodeValue :节点的值 3. nodeType ...

  4. MIT Scheme 的基本使用

    MIT Scheme 的基本使用 安装和启动 启动 在 Windows 下正确安装 MIT Scheme 系统后,程序菜单里将有一个 MIT Scheme 目录,其中包含: Documentation ...

  5. 解决DataSnap支持的Tcp长连接数受限的两种方法

    如何解决DataSnap支持的Tcp长连接数受限的问题? 方案一: 采用代理服务器方式,基本流程为: 1.客户先连接代理服务器:2.获取可用的服务器IP和端口:3.关闭与代理服务器之间的连接:4.建立 ...

  6. javascript 数组排序之 sort()

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...

  7. access_ok()

    access_ok() 函数是用来代替老版本的 verify_area() 函数的.它的作用也是检查用户空间指针是否可用. 函数原型: access_ok (type, addr, size); 变量 ...

  8. KAFKA分布式消息系统

    2015-01-05 大数据平台 Hadoop大数据平台 基本概念 kafka的工作方式和其他MQ基本相同,只是在一些名词命名上有些不同.为了更好的讨论,这里对这些名词做简单解释.通过这些解释应该可以 ...

  9. 【BZOJ 1026】 [SCOI2009]windy数

    Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B之间,包括A和B,总共有多少个windy数? In ...

  10. 【转载】Hadoop历史服务器详解

    免责声明:     本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除.     原文作者:过往记忆(http://www.iteblog.com/)     原文地址: ...