A:开场懵逼。然后发现有人1min过,于是就sort了一下,于是就过了。正经证明的话,考虑回文串两端点一定是相同的,所以最多有Σcnti*(cnti+1)/2个,cnti为第i种字母出现次数。而sort是可以达到这个最大值的。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
#define N 100010
int n;
char s[N];
int main()
{
n=read();
scanf("%s",s+);sort(s+,s+n+);
printf("%s",s+);
return ;
}

  B:注意到由一点到另一点向左和向右移动次数的差是固定的,所以只需要最小化他们的和。直接dij即可。实际上有一种01bfs的trick,用来跑边权只有01的最短路,使用一个deque,每次将0边扩展到的点放在队首,1边扩展到的点放在队尾,容易发现这样保证了队列里的点按距离排序。不过普通队列直接bfs的fst了一片。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
#define N 2010
int n,m,r,c,x,y,p[N*N],t,ans=;
int a[N][N],d[N*N];
bool flag[N*N];
struct data{int to,nxt,len;
}edge[N*N<<];
void addedge(int x,int y,int z){t++;edge[t].to=y,edge[t].nxt=p[x],edge[t].len=z,p[x]=t;}
int trans(int x,int y){return (x-)*m+y;}
struct data2
{
int x,d;
bool operator <(const data2&a) const
{
return d>a.d;
}
};
priority_queue<data2> q;
void dijkstra(int start)
{
while (!q.empty()) q.pop();
memset(d,,sizeof(d));d[start]=;q.push((data2){start,});
memset(flag,,sizeof(flag));
for (int i=;i<=n*m;i++)
{
while (!q.empty()&&flag[q.top().x]) q.pop();
if (q.empty()) break;
data2 v=q.top();q.pop();
flag[v.x]=;
for (int j=p[v.x];j;j=edge[j].nxt)
if (v.d+edge[j].len<d[edge[j].to])
{
d[edge[j].to]=v.d+edge[j].len;
q.push((data2){edge[j].to,d[edge[j].to]});
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),m=read(),r=read(),c=read(),x=read(),y=read();swap(x,y);
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
{
char c=getchar();
while (c!='.'&&c!='*') c=getchar();
if (c=='.') a[i][j]=;
}
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
if (a[i][j])
{
if (i>&&a[i-][j]) addedge(trans(i,j),trans(i-,j),);
if (j>&&a[i][j-]) addedge(trans(i,j),trans(i,j-),);
if (i<n&&a[i+][j]) addedge(trans(i,j),trans(i+,j),);
if (j<m&&a[i][j+]) addedge(trans(i,j),trans(i,j+),);
}
dijkstra(trans(r,c));
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
if (d[trans(i,j)]<=n*m)
{
//cout<<i<<' '<<j<<' '<<d[trans(i,j)]<<endl;
int p=(d[trans(i,j)]+j-c)/,q=d[trans(i,j)]-p;
if (p<=x&&q<=y)ans++;
}
//x+y=d x-y=j-c x right
//x=(d+j-c)/2 y=d-x
cout<<ans;
return ;
}

  C:将所有点放在一条线上,黑点划在一边白点划在一边,每次取未确定部分的中点,根据所给颜色继续划分。可能需要把第一个点放在最左或最右,不这么干的话最后可能会有重合点。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
#define N 35
int n,l,r;
int main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
cin>>n;l=,r=;
cout<<<<' '<<<<endl;
char ch=getchar();while (ch!='b'&&ch!='w') ch=getchar();
for (int i=;i<=n;i++)
{
cout<<<<' '<<(l+r)/<<endl;
fflush(stdout);
char c=getchar();while (c!='b'&&c!='w') c=getchar();
if (c==ch) l=(l+r)/;else r=(l+r)/;
while (c>='a'&&c<='z') c=getchar();
}
cout<<<<' '<<l<<' '<<<<' '<<r<<endl;
fflush(stdout);
return ;
}

  后面的神仙题不管了。

  本来是手速场结果C想了1h,BC加起来还wa了四发,于是就没救了。

  result:rank 226 rating +15

Codeforces Round#516 Div.1 翻车记的更多相关文章

  1. Codeforces Round#500 Div.2 翻车记

    A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...

  2. Codeforces Round#509 Div.2翻车记

    A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...

  3. Educational Codeforces Round 56 Div. 2 翻车记

    A:签到. B:仅当只有一种字符时无法构成非回文串. #include<iostream> #include<cstdio> #include<cmath> #in ...

  4. Educational Codeforces Round 55 Div. 2 翻车记

    A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...

  5. Codeforces Round#514 Div.2 翻车记

    A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...

  6. Codeforces Round #524 Div. 2 翻车记

    A:签到.room里有一个用for写的,hack了一发1e8 1,结果用了大概600+ms跑过去了.惨绝人寰. #include<iostream> #include<cstdio& ...

  7. Codeforces Round #517 Div. 1翻车记

    A:真的懵逼了.冷静了半天之后决定二分一下答案,然后先a安排上尽量小的再贪心地一个个扩大.40min才过.这个做法非常怂的以代码复杂度和时间复杂度为代价换取了比较稳的正确性,事实上由于1~n可以组合出 ...

  8. Educational Codeforces Round 53 Div. 2翻车记

    A:差点开场懵逼.只要有相邻两位不同就可以作为答案. #include<iostream> #include<cstdio> #include<cmath> #in ...

  9. Codeforces Round #394 (Div. 2) 颓废记

    昨天晚上(今天凌晨),又忍不住去打CF.(本蒟弱到只能打Div.2)... 我觉得我可以用一个词概括我这次的CF: 呵呵 刚一开赛,我就codeforces访问失败.. 后来好不容易能上了,两三分钟才 ...

随机推荐

  1. LeetCode:39. Combination Sum(Medium)

    1. 原题链接 https://leetcode.com/problems/combination-sum/description/ 2. 题目要求 给定一个整型数组candidates[ ]和目标值 ...

  2. elasticsearch集群整合elqsticsearch-sql插件

    1.本来整合这个插件是比较简单易操作的,但是由于公司从AWS下载禁掉了,给安装带来一些麻烦, 采用离线安装,先FQ将elasticsearch-sql-5.1.2.0.zip下载下来: ./bin/e ...

  3. eclipse插件SCON的SConscript文件和头文件以及C文件包含路径

    1. 本次的头文件路径\Hi2110-B657SP3-SDK\src_release_657SP3\src\lib\onenet\public,以此例子作为研究,本次开发使用eclipse,用到SCO ...

  4. `Facebook.Unity.Settings' has already been imported error solution

    after import facebook sdk to unity, i get the '`Facebook.Unity.Settings' has already been imported' ...

  5. NavRouter

    使用方法只需要跟vue-router一样正常使用即可,这里我们新加了一个路由跳转方法nav: router.nav()//参数同router.replace一样. 路由跳转策略 首先说下路由跳转过程, ...

  6. 180531-Spring中JavaConfig知识小结

    原文链接:Spring中JavaConfig知识小结/ Sring中JavaConfig使用姿势 去掉xml的配置方式,改成用Java来配置,最常见的就是将xml中的 bean定义, scanner包 ...

  7. Linux命令应用大词典-第22章 GRUB

    22.1 grub-md5-crypt:使用MD5格式加密口令 22.2 grub-install:在设备上安装GRUB 22.3 grub:进入GRUB命令shell 22.4 grub-crypt ...

  8. 学好三角学(函数) — SWIFT和JAVASCRIPT游戏开发的必备技能 iFIERO.com

    不论是使用哪种平台进行开发,三角学在游戏当中都被广泛的使用,因此,小编iFERO认为,三角学是必须得掌握的技能之一. 游戏图片由 摘自 Razeware LLC 先以Javascript为例 一.角度 ...

  9. java学习笔记-8.对象的容纳

    1.Iterator(迭代器)和Enumeration(枚举类),都是用来遍历集合的,他们都是接口.区别是Enumeration只能读取集合的数据,而Iterator可以对数据进行删除,Iterato ...

  10. 剑指offer-从上往下打印二叉树22

    题目描述 从上往下打印出二叉树的每个节点,同层节点从左至右打印. class Solution: # 返回从上到下每个节点值列表,例:[1,2,3] def PrintFromTopToBottom( ...