Codeforces Round #289 Div 2
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的更多相关文章
- 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 ...
- 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 ...
- 贪心 Codeforces Round #289 (Div. 2, ACM ICPC Rules) B. Painting Pebbles
题目传送门 /* 题意:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色去填充所有存在的pebbles, 使得任意两个piles,用颜色c填充的pebbles数量 ...
- 递推水题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table
题目传送门 /* 模拟递推水题 */ #include <cstdio> #include <iostream> #include <cmath> #include ...
- 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 ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
随机推荐
- Core Java(四)
四.数组 数组就是主函数(main方法)中的参数:public static void main(String[] args){ }数组是指一组数据的集合,数组中的每个数据称为元素.在Java中 ...
- 达夫设备之js
最近阅读<高性能JavaScript>时,在书中的“达夫设备“ . 对此,有些感悟,同时有些疑问,希望看到的朋友,能帮忙解释下,在此先提前感谢了. 1. 先说自己的理解吧: ”达夫设备“的 ...
- swift使用查阅资料备份3
自主学习之RxSwift(二) -----flatMap https://blog.csdn.net/chelongfei/article/details/50995603 RxSwift 系列(九) ...
- 3Ds Max实例教程-制作女战士全过程
3Ds Max制作“女战神” 作者:Diego Rodríguez 使用软件:3Ds Max,Photoshop 3Ds Max下载:http://wm.makeding.com/iclk/?zone ...
- selenium基础
浏览器 selenium本质是通过驱动浏览器,完全模拟浏览器的操作,比如跳转.输入.点击.下拉等来拿到网页渲染之后的结果,可支持多种浏览器 官网链接:http://selenium-python.re ...
- Pyhton学习——Day7
##############################################匿名函数################################################## ...
- Maven private reprository 更新
maven对构件的更新判断基本上是两种,一种是稳定版本,一种是maven特有的SNAPSHOT版本. 稳定版本很好判断,直接根据maven构件的坐标体系就能够获得.先从本地仓库中找,如果本地仓库没有, ...
- react-redux源码解析(资料)
资料:https://www.cnblogs.com/hhhyaaon/p/5863408.html 感觉很棒,记录一下
- webpack初识(biaoyansu)
1.是什么和为什么 在浏览器中的js之间如果需要相互依赖 src=a.js src=b.js src=c.js src=d.js 需要暴露出全局变量,而暴露出的这个全局变量是非常不安全的, 随着Nod ...
- CF1037E Trips (离线+图上构造)
题目大意:一共有n个人,每天早上会有两个人成为朋友,朋友关系不具有传递性,晚上,它们会组织旅游,如果一个人去旅游,那么他不少于$k$个朋友也要和他去旅游,求每天的最大旅游人数 一开始并没有想到反向建图 ...