A. Maximum in Table

题意:给定一个表格,它的第一行全为1,第一列全为1,另外的数满足a[i][j]=a[i-1][j]+a[i][j-1],求这个表格中的最大的数

a[n][n]即为最大的数

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[12][12],n;
int main()
{
int i,j,max;
scanf("%d",&n);
memset(a,0,sizeof(a));
for(j=1;j<=n;j++)
a[1][j]=1;
for(i=1;i<=n;i++)
a[i][1]=1; for(i=2;i<=n;i++)
for(j=2;j<=n;j++)
{
a[i][j]=a[i-1][j]+a[i][j-1];
}
printf("%d\n",a[n][n]);
}

  

B. Painting Pebbles

题意:给定n堆卵石,以及k种颜色,现在给它们上色,要求任意两堆石头的颜色为c的石头个数相差小于等于1

首先将这n堆石头排序,如果k<max-min,那么肯定不能满足 如果k>max-min,那么一定是每一堆石头重复的颜色越少,越能够满足这个条件,所以对每一堆石头,就从第一种颜色开始涂色,依次涂上1 2 3 ---如果石头的个数超过了颜色的种类,则当前涂到第j个石头,用j对k取余,即为该石头的颜色。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int b[305][305];
struct node
{
int num;
int order;
} a[305];
bool cmp(node n1,node n2)
{
return n1.num<n2.num;
}
bool cmp0(node n1,node n2)
{
return n1.order<n2.order;
}
int main()
{
int n,k,i,j,ans;
scanf("%d %d",&n,&k);
memset(b,0,sizeof(b));
for(i=1;i<=n;i++)
{
scanf("%d",&a[i].num);
a[i].order=i;
}
sort(a+1,a+1+n,cmp); if(k<a[n].num-a[1].num)
printf("NO\n");
else
{
for(i=1;i<=n;i++)
{
for(j=1;j<=a[i].num;j++)
{
b[a[i].order][j]=j%k;
if(j%k==0)
b[a[i].order][j]=k;
}
}
printf("YES\n");
sort(a+1,a+n+1,cmp0);
for(i=1;i<=n;i++)
{
for(j=1;j<=a[i].num;j++)
printf("%d ",b[a[i].order][j]);
printf("\n"); }
} }

 E. Pretty Song

题意:给出一串字符串,规定如果字母是A,E,I,O,U,Y,它的值为1,否则其值为0,    w=该子串中元音字母的个数(即有多少个1)/  该子串的长度

我们要计算的就是所有w的和

下面的思路是借鉴别人的思路---

可以令sum[i]为以第i个字母结尾有多少个元音字母,

当子串的长度为1的时候,每个字符都被计算了一次 tmp+=sum[len]-sum[1]

当子串的长度为2的时候,每个字符除了第一个字符和最后一个字符计算一次,其余的都被计算了两次,所以tmp+=sum[len-1]-sum[2]

以样例 Y I S V O W E L为例

长度为1的子串 Y,I,S,V,O,W,E,L 每个字符都被计算了1次 tmp+=sum[len]-sum[0];

长度为2的子串 YI,IS,SV,VO,OW,WE,EL 所以可以看到除了首字母和最后一个字母都被计算了两次--

剩下的就可以以此类推----

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long sum[1000010],l,r,len,tmp;
char s[1000010];
int main()
{
int i;
double ans=0;
scanf("%s",s+1);
len=strlen(s+1);
memset(sum,0,sizeof(sum));
for(i=1;i<=len;i++)
sum[i]=sum[i-1]+1*(s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U'||s[i]=='Y'); l=0;
r=len;
for(i=1;i<=len;i++)
{
tmp+=sum[r]-sum[l];
ans+=tmp*1.0/i;
r--;l++;
}
printf("%.7lf\n",ans);
}

Codeforces Round #289 Div 2的更多相关文章

  1. codeforces水题100道 第十八题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/509/A题意:f[i][1]=f[1][i]=1,f[i][j]=f[i-1][j]+f[i][j ...

  2. Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song 算贡献+前缀和

    E. Pretty Song time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. 贪心 Codeforces Round #289 (Div. 2, ACM ICPC Rules) B. Painting Pebbles

    题目传送门 /* 题意:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色去填充所有存在的pebbles, 使得任意两个piles,用颜色c填充的pebbles数量 ...

  4. 递推水题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table

    题目传送门 /* 模拟递推水题 */ #include <cstdio> #include <iostream> #include <cmath> #include ...

  5. Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table【递推】

    A. Maximum in Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. layer.js漂亮的弹出框

    它的官方网站:http://layer.layui.com/ 消息.确认框.ifame.自定义文本.旋转木马,都有按钮,是一款强大的js 弹出框: 以下为本人的简单介绍: layer.open({ t ...

  2. usaco 最少找零

    Description 约翰在镇上买了 T 元钱的东西,正在研究如何付钱.假设有 N 种钞票,第 i 种钞票的面值为 Vi,约翰身上带着这样的钞票 Ci 张.商店老板罗伯是个土豪,所有种类的钞票都有无 ...

  3. px 与 pt

    px:pixel,像素,屏幕上显示的最小单位,用于网页设计,直观方便: pt:point,是一个标准的长度单位,1pt=1/72英寸,用于印刷业,非常简单易用: em:即%,在CSS中,1em=100 ...

  4. [OS][ linux ] 建立新帳號, 變更密碼, 加入 sudoer

    新增 linux , 設定預設 password, 新增 user 到 sudoers 1. 新增 User sudo useradd aa97 2. 設定 User password sudo pa ...

  5. Photoshop保存文件时的选项

    以 JPEG 格式存储 您可以使用"存储为"命令以 JPEG (*.jpg) 格式存储 CMYK.RGB 和灰度图像.JPEG 通过有选择地扔掉数据来压缩文件大小.也可以使用&qu ...

  6. php基础------将二维数组转三维数组

    将二维数组转为三维数组 /** * 二维数组转三维数组(指定键为三维数组的键名) * @param [type] $arr [要排序的数组] * @param [type] $key [指定的键] * ...

  7. unity 模型 材质 贴图 关系;着色器属性

    模型包含 材质(Material),包括 [核心]着色器(Shader) 贴图和其他参数,贴图也算是一种参数 其他,如网格渲染器(Mesh Renderer).动画.坐标 一个材质可以看做为一个Sha ...

  8. JS iframe给父类传值

    父类页面 <html><head> <script type="text/javascript">            function Ge ...

  9. Python 绘图与可视化 seaborn

    Seaborn是一个基于matplotlib的Python数据可视化库.它提供了一个高级界面,用于绘制有吸引力且信息丰富的统计图形. 主页:http://seaborn.pydata.org/ 官方教 ...

  10. Eclipse Maven 创建Hello World Web项目

    通过Eclipse创建Maven Web项目的简单步骤 先决条件 (Prerequisites) 1,JDK  environment, 具体的安装JDK的步骤和环境配置一般网上都有,这里就不在赘述. ...