Codeforces Round #265 (Div. 2)
http://codeforces.com/contest/465
rating+7,,简直。。。
感人肺腑。。。。。。。。。。。。。。。蒟蒻就是蒟蒻。。。。。。。。。
被虐瞎
a:inc ARG
题意:将串反过来后+1问有多少个位变化。。
。。我是模拟的。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=105;
int a[N], n;
int main() {
read(n);
char s[N];
scanf("%s", s);
rep(i, n) a[i+1]=s[i]-'0';
a[1]+=1;
int t=a[1]/2, i=2, ans=1; a[1]%=2;
while(t && i<=n) {
a[i]+=t;
t=a[i]/2;
a[i]%=2;
i++;
++ans;
}
print(ans);
return 0;
}
题意:对一个01序列有3种操作,要求将所有的1变成0,求最小步数
1.从目录到达任意位置。(到达的地方1变成0,如果是0那么不变)
2.回到目录
3.向前或想后走一步
显然的贪心。。。
对于一个相连的块,要到达下一个块,最佳方案就是回到目录再到下一个块的初始位置,需要2步(尽管他们距离1,向前走也是需要2步)
对于同一个块内的点,直接往前走就行。。
然后模拟累计。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=1005;
int a[N], n;
int main() {
read(n);
for1(i, 1, n) read(a[i]);
int ans=-1;
for1(i, 1, n) {
while(a[i]==0 && i<=n) ++i;
if(i>n) break;
while(a[i]&&a[i+1] && i<=n) { ++i; ++ans; }
ans+=2;
}
if(ans==-1) ans=0;
print(ans);
return 0;
}
题意:给你一个没有长度为2以上(包括2)的回文串的一个字符串,然后让你求比他大的所有排列且没有长度为2以上(包括2)的下一个最小的排列。
剩下的1个半小时都在搞这题。。。。。。。。。。T_T
神题。。
我dfs写渣
判重写渣
然后滚粗。
这里有个贪心。
串的任意部分都不能是回文=串中任意连续3个字符互不相同
那么如果从左往右找,那么只需要判断x-1和x-2与x不等即可
其次我们要保证字典序最小,所以我们从右向左依次尝试修改,只要找到不符合回文条件的点,就修改它。这样保证了前边的最小。。
而且能证明,后边一定能构造出一个不是回文的串。例如m=4,我可以构造abcabcabc。。。。。。。。。。。。(x-1和x-2与x不等)
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=2015;
char str[N];
int n, m; inline const char fix(const int &p) {
char i;
for(i=str[p]+1; i<'a'+m; ++i)
if(str[p-1]!=i && str[p-2]!=i) return i;
return 0;
}
int main() {
read(n); read(m);
scanf("%s", str);
int len=strlen(str);
int i;
for(i=len-1; i>=0; --i) {
char t=fix(i);
if(t) { str[i]=t; break; }
}
if(i==-1) { puts("NO"); return 0; }
for(++i; i<len; ++i) {
str[i]='a'-1;
char t=fix(i);
if(t) str[i]=t;
}
printf("%s", str);
return 0;
}
d:没看。。
e:没看。。
Codeforces Round #265 (Div. 2)的更多相关文章
- Codeforces Round #265 (Div. 1) C. Substitutes in Number dp
题目链接: http://codeforces.com/contest/464/problem/C J. Substitutes in Number time limit per test 1 sec ...
- Codeforces Round #265 (Div. 2) C. No to Palindromes! 构建无回文串子
http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,如今要求输出一个字典比s大的字符串,且串中字母在一定 ...
- Codeforces Round #265 (Div. 2) E. Substitutes in Number
http://codeforces.com/contest/465/problem/E 给定一个字符串,以及n个变换操作,将一个数字变成一个字符串,可能为空串,然后最后将字符串当成一个数,取模1e9+ ...
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断
http://codeforces.com/contest/465/problem/D 给定8个点坐标,对于每个点来说,可以随意交换x,y,z坐标的数值.问说8个点是否可以组成立方体. 暴力枚举即可, ...
- Codeforces Round #265 (Div. 2) C. No to Palindromes! 构造不含回文子串的串
http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,现在要求输出一个字典比s大的字符串,且串中字母在一定 ...
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体推断
http://codeforces.com/contest/465/problem/D 给定8个点坐标.对于每一个点来说,能够任意交换x.y,z坐标的数值. 问说8个点能否够组成立方体. 暴力枚举就可 ...
- Codeforces Round #265 (Div. 2) E
这题说的是给了数字的字符串 然后有n种的操作没次将一个数字替换成另一个字符串,求出最后形成的字符串的 数字是多大,我们可以逆向的将每个数推出来,计算出他的值和位数记住位数用10的k次方来记 1位就是1 ...
- Codeforces Round #265 (Div. 2) B. Inbox (100500)
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others ...
- Codeforces Round #265 (Div. 1)
D. World of Darkraft - 2 time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
随机推荐
- Xcode 生成 ipa包
原地址:http://zengwu3915.blog.163.com/blog/static/2783489720136213239916/ app store的审核收费的需要二周,免费的需要一个月左 ...
- Laravel 隐藏域如何实现?
Laravel 隐藏域如何实现? 在 Blade 模板中,我们可以使用 method_field 方法来创建隐藏域. {{ method_field('DELETE') }} 其转化为 HTM ...
- Nginx如何保留真实IP和获取前端IP
原理: squid,varnish以及nginx等,在做反向代理的时候,因为要代替客户端去访问服务器,所以,当请求包经过反向代理后,在代理服务器这里这个IP数据包的IP包头做了修改,最终后端web服务 ...
- pageEncoding和ContextType区别
http://blog.csdn.net/kerrywang/article/details/4454895 pageEncoding 在JSP标准的语法中,如果 pageEncodin ...
- CSS:给 input 中 type="text" 设置CSS样式
input[type="text"], input[type="password"] { border: 1px solid #ccc; paddi ...
- JavaScript 中的所有数据都是以 64 位浮点型数据(float) 来存储。浮点型数据使用注意事项。全局变量特殊之处
JavaScript 中的所有数据都是以 64 位浮点型数据(float) 来存储. 所有的编程语言,包括 JavaScript,对浮点型数据的精确度都很难确定: <!DOCTYPE html& ...
- C# 编写Windows服务在VS中调试的步骤
1.以管理员身份运行cmd 2.安装windows服务 cd C:\Windows\Microsoft.NET\Framework\v4.0.30319(InstallUtil.exe的路径,注意In ...
- java语言国际化--ResouceBundle、struts
一.Java国际化 我们使用java.lang.Locale来构造Java国际化的情境. java.lang.Locale代表特定的地理.政治和文化.需要Locale来执行其任务的操作叫语言环境敏感的 ...
- 如何查看Linux操作系统的位数
如何查看Linux操作系统的位数 1.编程实现: 在程序中返回sizeof(int)的值,返回的结果是操作系统的字节数.若返回4则是32位操作系统,返回8即是64位. 2.2.getconf命令: g ...
- C++ vector 和 map的删除
1.连续内存序列容器(vector,string,deque) 序列容器的erase方法返回值是指向紧接在被删除元素之后的元素的有效迭代器,可以根据这个返回值来安全删除元素. vector<in ...