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;
}

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;
}

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;
}

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); }

  

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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces round 419 div2 补题 CF 816 A-E

    A Karen and Morning 水题 注意进位即可 #include<bits/stdc++.h> using namespace std; typedef long long i ...

  4. codeforces round 417 div2 补题 CF 812 A-E

    A Sagheer and Crossroads 水题略过(然而被Hack了 以后要更加谨慎) #include<bits/stdc++.h> using namespace std; i ...

  5. codeforces round 416 div2 补题 CF 811 A B C D E

    A. Vladik and Courtesy 水题略过 #include<cstdio> #include<cstdlib> #include<cmath> usi ...

  6. codeforces round 420 div2 补题 CF 821 A-E

    A Okabe and Future Gadget Laboratory 暴力 #include<bits/stdc++.h> using namespace std; typedef l ...

  7. Educational Codeforces Round 23 A-F 补题

    A Treasure Hunt 注意负数和0的特殊处理.. 水题.. 然而又被Hack了 吗的智障 #include<bits/stdc++.h> using namespace std; ...

  8. codeforces 447 A-E div2 补题

    A DZY Loves Hash 水题 #include<iostream> #include<cstdio> #include<cstdlib> #include ...

  9. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

随机推荐

  1. hdu 1824 2-sat问题(判断)

    /* 题意:u,v,w队长,队员,队长留下两个队员可以回家,两个队员留下,队长回家 2-sat问题,把两个队员看成一个整体就变成一个简单2-sat问题了 */ #include<stdio.h& ...

  2. 两行代码快速创建一个iOS主流UI框架

    本框架适用于 使用 NavigationController+UITabBarController 的APP 框架QLSNavTab , GitHub地址:https://github.com/qia ...

  3. 2017"百度之星"程序设计大赛 - 初赛(A)数据分割

    n<=100000条相等/不等关系描述<=100000个数,把这些数据分割成若干段使得每一段描述都出现冲突且冲突只出现在最后一行. 相等关系具有传递性,并查集维护:不等关系根据相等关系进行 ...

  4. 内存管理——(exceptional C++ 条款9,条款10)

    C++的各个内存区域: (1)常量数据(const data)区 常量数据区存储的是字符串等在编译期间就能确定的值,在整个程序的生命周期内,这里的数据都是可用.区域内所有的数据都是 只读的. (2)栈 ...

  5. ***ps -ef |grep 输出的具体含义是什么?

    Q: 比如:[root@localhost ~]# ps -ef | grep ApacheJetspeedroot 18887 18828 0 08:09 pts/0 00:00:00 grep A ...

  6. linux 开机启动脚本或者服务

    https://blog.csdn.net/zhuchunyan_aijia/article/details/53811368

  7. Hadoop经典书籍资料收藏(35本)转

    原文地址:http://www.hadoopor.com/thread-5128-1-2.html 1."Hadoop.Operations.pdf.zip" http://vdi ...

  8. zookeeper一二三

    1.zookeeper介绍 ZooKeeper 是一个开源的分布式协调服务,由雅虎创建,是 Google Chubby 的开源实现.分布式应用程序可以基于 ZooKeeper 实现诸如数据发布/订阅. ...

  9. Spring的JDBC示例

    以下内容引用自http://wiki.jikexueyuan.com/project/spring/jdbc-framework-overview/spring-jdbc-example.html: ...

  10. Go---设计模式(策略模式)

    策略模式定义了算法家族,在调用算法家族的时候不感知算法的变化,客户也不会受到影响. 下面用<大话设计模式>中的一个实例进行改写. 例:超市中经常进行促销活动,促销活动的促销方法就是一个个策 ...