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. Java NIO(六)选择器

    前言 Selector选择器是Java NIO中能够检测一到多个NIO通道,并能够知晓通道是否为诸如读写事件做好准备的组件.这样使得一个单独的线程可以管理多个Channel,从而管理多个网络连接.选择 ...

  2. 使用pgpool管理数据库集群故障的问题

    pgpool如何选举master角色 在pgpool启动的过程中通过对 pgpoo.conf配置文件中的数据库节点条目信息,对集群中的数据库节点从0开始一个个的遍历,并发送SQL语句“select p ...

  3. 前端框架easyui layout, Tabs,tree

    一.三大前端框架的 1.easyui=jquery+html4(用来做后台的管理界面) 不要钱,开发速度快,不好看,不支持响应式 2.bootstrap=jquery+html5 好看,开发速度快,部 ...

  4. SOAP扩展PHP轻松实现WebService

    最近在一个PHP项目中对接外部接口涉及到WebService,搜索引擎上相关文章不是很多,找到的大都是引用一个号称很强大的开源软件 NuSOAP(下载地址:http://sourceforge.net ...

  5. vue项目初始化步骤

    项目初始化:() 1. 安装vue-cli :    npm install -g vue-cli 2.初始化项目:   vue init webpack  my-project 3.进入项目:  c ...

  6. SPOJ CIRU

    SPOJ CIRU 题意 给出n个圆,求他们覆盖的面积. 解法 自适应Simpson,但需要将圆离散化一下,以保证我们查询的是一个连续的有圆的区间. 奇怪的是我没有离散化,样例都没有过,却把题给A了 ...

  7. 移动设备safari不支持jquery的live绑定的解决方案

    给元素加上样式如下即可 <style> .btn{ cursor: pointer; } </style>

  8. WinServer-IIS初始安装及发布网站

    \aspnet_regiis.exe –i 还有非常重要的一步就是给发布文件夹设置权限,到底设置那一个用户的权限我也没有弄清楚,大概是IIS_IUSERS或者IUSR用户就可以了,我设置完了之后没有反 ...

  9. LeetCode OJ 之 Number of Digit One (数字1的个数)

    题目: Given an integer n, count the total number of digit 1 appearing in all non-negative integers les ...

  10. weblogic部署struts2项目訪问action404错误

    近期有个project部署到tomcat上是正常的,部署到weblogic上时訪问action报404错误.依据报错日志.在网上找到了原因例如以下: 部署到weblogic上.struts.xml配置 ...