URAL 2026 C - Dean and Schedule
来源:互联网 发布:2016淘宝小号批量注册 编辑:程序博客网 时间:2024/05/26 07:30
/*PROBLEM C : DEAN AND SCHEDULE "UNSOLVED" */#include "cstdio"#include "cstring"#include "cctype"#include "algorithm"using namespace std;#define Inc(i, a, b) for(int i = a; i < b; i++)#define Dec(i, a, b) for(int i = a; i > b; i--)#define Mem(a) memset(a, 0, sizeof(a))#define Pii pair<int, int> #define Cin scanf#define Put printf#define CIN(a) scanf("%d", &a)#define CII(a, b) scanf("%d%d", &a, &b)#define CIS(a) scanf("%s", a)#define PUT(a) printf("%d\n", a) #define PII(a, b) printf("%d %d\n", a, b)#define PUS(a) printf("%s\n", a)#define ll long long#define maxn 100005char st[maxn];int k, len;int is[27];void Update() {Inc(i, 0, len) if(st[i] == '?') st[i] = (i & 1 ? 'a' : 'z');}int main() {CIS(st), CIN(k);len = strlen(st);if(len < k) {PUT(-1); return 0;}Mem(is);bool flag = 1;int t0 = 0;int odd = 0, even = 0;Inc(i, 0, len) {if(st[i] == '?') {flag = 0, t0++;if(i & 1) even++;else odd++;}else is[st[i] - 'a'] = 1;}int t1 = 0;Inc(i, 0, 26) t1 += is[i];if(flag) {if(t1 >= k) PUS(st); else PUT(-1); return 0;}if(t0 + t1 < k) {PUT(-1); return 0;}if(t1 >= k) {Update();PUS(st); return 0;}int al = 0, ar = 25;if(!is[0] && even) {Inc(i, 0, len) if((i & 1) && st[i] == '?') {is[0] = 1, even--;st[i] = 'a', t1++; break;}}if(!is[25] && odd) {Inc(i, 0, len) if((i % 2 == 0) && st[i] == '?') {is[25] = 1, odd--;st[i] = 'z', t1++; break;}}int so = 0, se = 1;while(t1 < k) {Inc(i, so, len) if((i % 2 == 0) && st[i] == '?') {so = i; break;}Inc(i, se, len) if((i & 1) && st[i] == '?') {se = i; break;}Inc(i, al, ar + 1) if(!is[i]) {al = i; break;}Dec(i, ar, al - 1) if(!is[i]) {ar = i; break;}if(odd == 0) {Inc(i, se, len) {if(st[i] == '?') {if(t1 < k) {st[i] = 'a' + al;is[al] = 1, t1++;Inc(i, al, ar + 1) if(!is[i]) { al = i; break;}} else st[i] = 'a';}} break;} else if(even == 0) {Inc(i, so, len) {if(st[i] == '?') {if(t1 < k) {st[i] = 'a' + ar;is[ar] = 1, t1++;Dec(i, ar, al - 1) if(!is[i]) { ar = i; break;} } else st[i] = 'z';}} break;}if(25 - al < ar) {st[so] = 'a' + ar, odd--;is[ar] = 1, t1++;} else {st[se] = 'a' + al, even--;is[al] = 1, t1++;}}Update();PUS(st);}
0 0
- URAL 2026 C - Dean and Schedule
- C - Dean and Schedule --贪心
- URAL 2026 Dean and Schedule 贪心、双端队列(deque)、队列(queue)
- Hurricane Dean and Tango_004
- Ural 1550 Dean's Pyramid 3
- ural 1550 Dean's Pyramid 3计算几何
- linux schedule and queue
- C - Task schedule-二分
- schedule mm_struct and CPU register
- URAL 1776 C
- URAL 1026. Questions and answers
- ural 1026 Questions and Answers
- hdu 3068 and ural 1297
- Ural 1548 Sakura and Statistics
- URAL:1200 Horns and Hoofs
- Ural 1430. Crime and Punishment
- Ural 1195 Ouths and Crosses
- URAL 1635. Mnemonics and Palindromes
- [leetcode] 242.Valid Anagram
- hihoCoder 1062 最近公共祖先·一
- VB.net工程的引用修改问题
- 偷西瓜(SPFA运用链式前向星来记录路径+删除路径+求最短路和次短路)
- Linux性能监控工具sysstat系列:介绍与安装
- URAL 2026 C - Dean and Schedule
- 每一个优秀的人,都有一段沉默的时光,是那一段时光,不抱怨不诉苦,最后渡过了这段感动自己的日子
- 图层损坏 E/ArcGIS﹕ The map or layer has been destroyed or recycled. 资源未释放
- 猴子
- 黑马程序员-多线程基础知识1
- Java之克隆
- vector培训
- 朴素贝叶斯分类算法(Naive Bayesian classification)
- hihoCoder 1066 无间道之并查集