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. SpringBoot(十) 异步任务,定时任务和邮件任务

    异步任务 “异步调用”对应的是“同步调用”,同步调用指程序按照定义顺序依次执行,每一行程序都必须等待上一行程序执行完成之后才能执行:异步调用指程序在顺序执行时,不等待异步调用的语句返回结果就执行后面的 ...

  2. node操作mysql插入数据异常,incorrect string value

    产生的原因 我在创建表的时候,并没有设定字符编码,所以,默认的字符编码是 latin1 在我插入数据的时候,我的一个字段name设定的是varchar(20) 其实,这时的编码就是 latin1 所以 ...

  3. What is the difference between arguments and parameters?

    What is the difference between arguments and parameters? Parameters are defined by the names that ap ...

  4. GRpc-Proto3语法

        syntax = "proto3"; 文件的第一行指定了你使用的是proto3的语法:如果你不指定,protocol buffer 编译器就会认为你使用的是proto2的语 ...

  5. PHP学习过程中遇到的疑难杂症

    变量当双引号中包含变量时,变量会与双引号中的内容连接在一起:当单引号中包含变量时,变量会被当做字符串输出. Heredoc结构形式首先使用定界符表示字符串(<<<),接着在“< ...

  6. Spring Batch 高级-

    spring batch / 并行处理 / 多线程 分区 1. 并行处理,多线程,分区 http://blog.csdn.net/github_36849773/article/details/692 ...

  7. 关于表格元素的使用,table、<width>、<heigh>、<border>、<tr>、<th>、<td>、<align>、<colspan>、<rowspan>

    <html>    <head>        <meta charset="UTF-8">        <title>个人简历& ...

  8. 连连看 HDU - 1175_搜索_剪枝

    hdu有毒,考试上 AC 的就是一直 WA- 其实这道题是可以进行初始化来进行优化的,这样的话询问次数是可以达到 10510^5105 的.不过普通的 dfsdfsdfs + 剪枝也是可过的. Cod ...

  9. Robot Framework自动化框架搭建的步骤

    我把自己之前搭建Robot Framework自动化测试框架的步骤整理了一下,感兴趣的同学可以参考一下.   Robot Framework自动化测试框架+ 可视化编辑工具RIDE+Selenium2 ...

  10. laravel contains 的用法

    最近在学laravel,做一下学习笔记. 1.contains()方法判断集合是否包含给定的项目: ]);var_dump($collection->contains('Desk'));// t ...