codeforces round 418 div2 补题 CF 814 A-E
A An abandoned sentiment from past
水题
#include<bits/stdc++.h> using namespace std; int a[300],b[300],n,k;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{//freopen("t.txt","r",stdin);
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
for(int i=0;i<k;i++) scanf("%d",&b[i]);
sort(b,b+k,cmp );
for(int i=0,j=0;i<n&&j<k;i++)
{
if(a[i]==0)a[i]=b[j++];
}
for(int i=1;i<n;i++)
if(a[i]<=a[i-1]){printf("YES\n");return 0;}
printf("NO\n");
return 0;
}
B An express train to reveries
水题
#include<bits/stdc++.h> using namespace std;
const int N=2000;
int a[N],b[N],ans[N],color[N],n,vis[N]; int main()
{//freopen("t.txt","r",stdin);
scanf("%d",&n);
for(int i=0;i<n;i++)scanf("%d",&a[i]);
for(int i=0;i<n;i++)scanf("%d",&b[i]);
int sum=0;
vector<int>ad;
ad.clear();
for(int i=0;i<n;i++)
if(a[i]==b[i])ans[i]=a[i],sum++,color[a[i]]++;
else ad.push_back(i);
vector<int>numa;
numa.clear();
for(int i=1;i<=n;i++)
if(color[i]==0)numa.push_back(i);
if(sum==n-1)
{
ans[ad[0]]=numa[(int)(numa.size()-1)];
}
else
{
if((a[ad[0]]==numa[0]&&b[ad[1]]==numa[1])||(b[ad[0]]==numa[0]&&a[ad[1]]==numa[1]))
{
ans[ad[0]]=numa[0];
ans[ad[1]]=numa[1];
}
else
{
ans[ad[1]]=numa[0];
ans[ad[0]]=numa[1];
}
}
for(int i=0;i<n-1;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[n-1]);
return 0;
}
C An impassioned circulation of affection
水题
#include<bits/stdc++.h> using namespace std; int dp[26][1510][1510],maxx[26][1510],ti[26][1510],n,q;
char ss[1510];
int main()
{//freopen("t.txt","r",stdin);
scanf("%d",&n);
scanf("%s",&ss);
for(int i=0;i<26;i++)
for(int j=0;j<n;j++)
{
int k=j;
while(k<n&&ss[k]==char(i+'a'))ti[i][j]++,k++;
}
for(int i=0;i<26;i++)
{
for(int j=0;j<n;j++)
{
for(int k=1;j+k<=n;k++)
{
if(dp[i][j][k-1]>=n){dp[i][j][k]=n;maxx[i][k]=max(maxx[i][k],dp[i][j][k]);continue;}
dp[i][j][k]=dp[i][j][k-1]+ti[i][min(n,j+dp[i][j][k-1])]+1+ti[i][min(n,j+dp[i][j][k-1]+ti[i][j+dp[i][j][k-1]]+1)];
if(dp[i][j][k]>n)dp[i][j][k]=n;
maxx[i][k]=max(maxx[i][k],dp[i][j][k]);
} }
}
//memset(dp,0,sizeof(dp));
scanf("%d",&q);
for(int i=0;i<q;i++)
{
char c;int jk;
getchar();
scanf("%d %c",&jk,&c);
int num=c-'a';
printf("%d\n",min(n,maxx[num][jk]));
}
return 0;
}
D An overnight dance in discotheque
比较难的一道贪心题
可以证明 只要把最底层的圆扔到另一个半场 就达到了最优态
为什么呢?
在这个状态下无论我们怎么移动 都无法让答案变好。
简单证明一下:
我们可以把任意几个圆(顺序无关)扔到底层圆上,
这几个圆组成的覆盖,对某些面积(sb)进行了偶数次覆盖,对某些面积(sa)进行了奇数次覆盖。
而被覆盖的最底层圆,所有的面积都被奇数次(1次)覆盖,而偶数次的覆盖无法改变奇偶性,
奇数次的覆盖会将原本所有的奇数次覆盖变成偶数次覆盖(同时将偶数次覆盖变成奇数次)。
所以我们想要移动的这些圆无论处在什么位置 都比放在底层圆上对答案贡献大
所以往单独在另一半场的底层圆(最大圆)移动任何圆的集合都不会让答案变好。
而所有的状态都可以从这个状态移动得到!
代码很简单(我这个蒟蒻想了半天DP方程 然而 O(n)贪心)
#include <bits/stdc++.h>
using namespace std; typedef long long LL; const long double pi = 3.14159265358979; #define N 100010 int x[N], y[N], r[N], dep[N], n; LL dist(int x, int y){ return 1ll * x * x + 1ll * y * y; } int main(){ ///freopen("in.txt", "r", stdin); scanf("%d", &n); for(int i = 1; i <= n; i ++){
scanf("%d %d %d", x + i, y + i, r + i);
} for(int i = 1; i <= n; i ++){
for(int j = 1; j <= n; j ++)if(r[j] > r[i]) {
if( dist( x[i] - x[j], y[i] - y[j]) <= 1ll * r[j] * r[j] ){
dep[i] ++;
}
}
} LL ans = 0; for(int i = 1; i <= n; i ++){
if(dep[i] == 0) ans += 1ll * r[i] * r[i];
else if(dep[i] & 1) ans += 1ll * r[i] * r[i];
else ans -= 1ll * r[i] * r[i];
} long double res = pi * ans; printf("%.10lf\n", (double) res); }
E An unavoidable detour for home
非常具有技巧性的一道计数题
题目给定一个图的某些性质,要求我们构造一个层次图。每个点要么连接2个点要么连接3个点。
求不同的构图方法数量。
我们通过分层来计数。
solve(i,f)表示解决a[i]之后的序列答案,且第一层有f个元素。
connect(two,three,after)表示对于当前层次,有two个节点需连接2个节点,有three个节点要连接3个点,且构图后有after个可连接位(即下一层需要after个节点)
剩下的看代码吧 关键地方注释了 connect函数的转移非常有趣
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#define f(i,n) for(LL i=0;i<(n);i++) const LL M=1e9+7; LL n,d[50],cn[51][51][51],sl[51][51],n3[51]; LL connect(LL twos, LL threes, LL after){
if(twos<0||threes<0) return 0;
LL &cur=cn[twos][threes][after];
if(cur!=-1) return cur;
if(after) return cur=(twos*connect(twos-1,threes,after-1)%M//拿出一个two
+threes*connect(twos+1,threes-1,after-1)%M)%M;//拿出一个three 向下有一个空位 相当于增加了一个two
if(twos) return cur=((twos-1)*connect(twos-2, threes, after)%M//选出一对two互相连接
+threes*connect(twos,threes-1,after)%M)%M;//选出一个three和一个two连接后变成一个two
if(!threes) return 1;
return cur=((threes-1)*(threes-2)/2)*connect(2,threes-3,0)%M;//选出三个three后相当于增加了2个two } LL solve(LL i, LL f){
if(i+f>n) return 0;
if(i==n) return f==0;
if(f==0) return 0;
LL &cur=sl[i][f];
if(~cur) return cur;
LL r=0, threes=n3[i+f]-n3[i], twos=f-threes;
for(LL cl=0;cl<=n-(i+f);cl++)
r = (r+connect(twos, threes, cl)*solve(i+f,cl)%M)%M;
return cur=r;
} main(){freopen("t.txt","r",stdin);
ios::sync_with_stdio(0),cin.tie(0);
memset(cn,-1,sizeof(cn));
memset(sl,-1,sizeof(sl));
cin>>n;
f(i,n){
cin>>d[i];
n3[i+1]=n3[i]+(d[i]==3);
}
cout<<solve(1,d[0])<<'\n';
}
俩小时做了三道水题 还被Hack了一道 该拿什么拯救我的coding? 我这么菜可怎么办??
codeforces round 418 div2 补题 CF 814 A-E的更多相关文章
- codeforces round 422 div2 补题 CF 822 A-F
A I'm bored with life 水题 #include<bits/stdc++.h> using namespace std; typedef long long int LL ...
- codeforces round 421 div2 补题 CF 820 A-E
A Mister B and Book Reading O(n)暴力即可 #include<bits/stdc++.h> using namespace std; typedef lon ...
- Codeforces round 419 div2 补题 CF 816 A-E
A Karen and Morning 水题 注意进位即可 #include<bits/stdc++.h> using namespace std; typedef long long i ...
- codeforces round 417 div2 补题 CF 812 A-E
A Sagheer and Crossroads 水题略过(然而被Hack了 以后要更加谨慎) #include<bits/stdc++.h> using namespace std; i ...
- codeforces round 416 div2 补题 CF 811 A B C D E
A. Vladik and Courtesy 水题略过 #include<cstdio> #include<cstdlib> #include<cmath> usi ...
- codeforces round 420 div2 补题 CF 821 A-E
A Okabe and Future Gadget Laboratory 暴力 #include<bits/stdc++.h> using namespace std; typedef l ...
- Educational Codeforces Round 23 A-F 补题
A Treasure Hunt 注意负数和0的特殊处理.. 水题.. 然而又被Hack了 吗的智障 #include<bits/stdc++.h> using namespace std; ...
- codeforces 447 A-E div2 补题
A DZY Loves Hash 水题 #include<iostream> #include<cstdio> #include<cstdlib> #include ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
随机推荐
- 【多校训练2】HDU 6047 Maximum Sequence
http://acm.hdu.edu.cn/showproblem.php?pid=6047 [题意] 给定两个长度为n的序列a和b,现在要通过一定的规则找到可行的a_n+1.....a_2n,求su ...
- Hibernate 批处理(batch inserts, updates and deletes)
总结:hibernate在进行批量处理不给力的主要原因就是Session中存在缓存,而hibernate的机制就是通过session中的一级缓存去同步数据库,所以当进行批量处理时,缓存中保存的数据量很 ...
- Flask处理前端POST过来的JSON数据
POST JSON数据的JS代码: $.ajax({ url:'http://127.0.0.1:5000/calc', type : 'post', dataType:'json', headers ...
- 收集整理Android开发所需的Android SDK、开发中用到的工具、Android开发教程、Android设计规范,免费的设计素材等。
AndroidDevTools Android Dev Tools官网地址:www.androiddevtools.cn 收集整理Android开发所需的Android SDK.开发中用到的工具.An ...
- 【CF766D】Mahmoud and a Dictionary(并查集)
题意:有n个单词,给定m个关系,每个关系要么表示单词a与单词b相同,要么表示单词a与单词b相反. 并且“相同”与“相反”有性质:若a与b相同,b与c相同,则a与c相同(从而单词的相同关系是等价关系): ...
- msp430项目编程04
msp430中项目---TFT彩屏显示 1.TFT彩屏工作原理 2.电路原理说明 3.代码(静态显示) 4.代码(动态显示) 5.项目总结 msp430项目编程 msp430入门学习
- solr请求处理器列表
List of Request Handlers Available The Javadocs contain a complete list of Request Handlers. Many of ...
- BZOJ 1123 tarjan
题目链接 题意:一张无向图,把第$i$个点关联的所有边去掉,求无向图中有多少个点对不连通. 题解: 如果割的不是割点,那么总答案是$2\times (n-1)$. 如果是割点,要分别考虑每个子树的贡献 ...
- POJ 1753 Flip Game【枚举】
题目链接: http://poj.org/problem?id=1753 题意: 由白块黑块组成的4*4方格,每次换一个块的颜色,其上下左右的块也会被换成相反的颜色.问最少换多少块,使得最终方格变为全 ...
- P1427 小鱼的数字游戏 洛谷
https://www.luogu.org/problem/show?pid=1427 题目描述 小鱼最近被要求参加一个数字游戏,要求它把看到的一串数字(长度不一定,以0结束,最多不超过100个,数字 ...