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又掉了……但是没什么,比上一次好多了: ...
随机推荐
- [Go]指针操作
指针类型比较常见 type Dog struct { name string } func (dog *Dog) SetName (name string){ dog.name = name } 对于 ...
- Docker安装redis操作命令
最近学习了redis,那么今天我们来学习以下在Docker上安装我们的redis,并查看有关redis的一系列命令 查找redis docker search redis 拉取redis docker ...
- Objective-c写冒泡排序
做面试题遇到用obj-c写冒泡排序,随便写了个 - (NSMutableArray *)sorted:(NSMutableArray *)array { int len = [array count] ...
- 【转载】epoll与select/poll的区别总结
因为这道题目经常被问到.干脆总结一下,免得遗漏了. 参考文章:http://www.cnblogs.com/qiaoconglovelife/p/5735936.html 1 本质上都是同步I/O 三 ...
- ECC数据结构
在SM2 ECC算法中,有针对签名加密的数据结构,下面对这些结构进行分析 #define ECCref_MAX_BITS 512 #define ECCref_MAX_LEN ((ECCref_MAX ...
- ArcGIS Engine 10.2 如何发布服务
http://blog.csdn.net/arcgis_all/article/details/17376397 1 ArcGIS Engine 10.2 如何发布服务 ArcGIS Engine的代 ...
- DLL混淆
- POI 的使用
POI 使用 一. POI简介 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能..NET的开发人员则 ...
- HLJU 1220: AC100天 (枚举)
1220: AC100天 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 89 Solved: 12 [id=1220">Submit ...
- Mysql Solution - Timeout error occurred trying to stop MySQL Daemon. Stopping MySQL: [FAILED] -
错误例如以下: Timeout error occurred trying to stop MySQL Daemon. Stopping mysqld: ...