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又掉了……但是没什么,比上一次好多了: ...
随机推荐
- devstack脚本安装Openstack总结(转载)
1:vmware 基本设置 我采用的vmware workstation 8.0的版本,其他版本应该都是没问题.我是把虚拟机放在NAT的网络. 虚拟机就单块网卡就可以. 如果你希望可以在dashboa ...
- 把disable maven nature后的项目,恢复菜单呈现出来(Convert to Maven Project)
把disable maven nature后的项目,恢复菜单呈现出来(Convert to Maven Project) 有的时候需求把disable maven nature后的项目,再转换为mav ...
- ORACLE备份、恢复、常用查询
--第一,启动服务,(如果数据库处于启动状态,那么略过这一步) 打开命令行执行以下语句 net start OracleServiceORCL net start OracleOraDb10g_ ...
- 安卓巴士Android开发神贴整理
10个经典的Android开源应用项目 http://www.apkbus.com/android-13519-1-1.html 安卓巴士总结了近百个Android优秀开源项目,覆盖Android开发 ...
- linux下程序JDBC连接不到mysql数据库
今天在linux下部署一个 JavaEE项目的时候总是连接不到Mysql数据库,检查之后发现连接池的配置确定是对的,进入linux服务器之后以mysql -uname -ppassword连接总是报A ...
- Wannafly模拟赛2 B river(拉格朗日乘数法)
题目 https://www.nowcoder.com/acm/contest/4/B题意 有n条南北流向的河并列排着,水流速度是v,现在你需要从西岸游到东岸,总共T个时间,你的游泳速度是u,问东岸的 ...
- 如何使用eclipse for c/c++ 配置环境编写第一个C程序
因为VS太大还要安装太多的插件,,,所以想用eclipse编写C语言... 1.下载eclipse for c/c++版本 去官网即可下载 https://www.eclipse.org/dow ...
- Android远程服务
一.远程服务主要代码 1.IService.aidl package com.shz.remoteservice; interface IService { String getTicketInfoB ...
- 2003 -Can't connection to mysql server on | navicat for mysql Access denied for user 'root'@''ip'(using password :yes)
用本机windows上的Navicat for mysql链接虚拟机Linux的mysql数据库时,第一次连接的时候报的错误是 2003 -Can't connection to mysql serv ...
- Deepin-安装和卸载软件
一般默认厂商源安装软件 安装软件: 示例:sudo apt-get install xx 实例:sudo apt-get install nodejs 卸载软件: 示例:sudo apt-get -- ...