SDUT1114Single Contest codeforces883 I+M 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest
2017-11-16 17:06
561 查看
冗余之事何故在意?
专心啃干货多充实。
Codeforces883H 题, 比赛来的晚, 剩下半小时左右看这题。
分割成回文串。是个瞎暴力, 想了想思路有点毛病, 没下手。
补了一波, 还是学到了些小技巧, 就算是暴力,也会有技巧。
就是将奇数也要拆成偶数, 就剩一个这个字符。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#define inf 0x3f3f3f
#define ms(x) memset(x, 0, sizeof(x))
using namespace std;
const int N = 512345;
char s[512345];
int book[123];
vector<char >od, ev;
int main()
{
int n;
scanf("%d",&n);
scanf("%s",s);
ms(book);
od.clear();
ev.clear();
for(int i=0; i<n; i++)
book[s[i]]++;
for(int i=0; i<123; i++)
{
if(book[i]!=0)
{
if(book[i]&1)
{
od.push_back((char)i);
book[i]--;
}
while(book[i])
{
ev.push_back(i);
book[i] -= 2;
}
}
}
char ans
;
int k = 0;
if(od.size()==0)
{
printf("1\n");
for(int i=0; i<n/2; i++)
{
ans[i] = ans[n-1-i] = ev[k++];
}
printf("%s",ans);
cout<<endl;
}
else
{
while(ev.size()%od.size())
{
od.push_back(ev.back());
od.push_back(ev.back());
ev.pop_back();
}
int len = n/od.size();
printf("%d\n", od.size());
for(int i=0;i<od.size();i++)
{
ans[len/2] = od[i];
for(int j=0;j<len/2;j++)
{
ans[j] = ans[len-1-j] = ev[k++];
}
ans[len]='\0';
if(i!=od.size()-1) printf("%s ",ans);
else printf("%s\n", ans);
}
}
4000
return 0;
}
CodeForces - 883I
感觉确实需要搞一下这些DP。。。 要不然真到了题解都看不懂的地步了
专心啃干货多充实。
Codeforces883H 题, 比赛来的晚, 剩下半小时左右看这题。
分割成回文串。是个瞎暴力, 想了想思路有点毛病, 没下手。
补了一波, 还是学到了些小技巧, 就算是暴力,也会有技巧。
就是将奇数也要拆成偶数, 就剩一个这个字符。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#define inf 0x3f3f3f
#define ms(x) memset(x, 0, sizeof(x))
using namespace std;
const int N = 512345;
char s[512345];
int book[123];
vector<char >od, ev;
int main()
{
int n;
scanf("%d",&n);
scanf("%s",s);
ms(book);
od.clear();
ev.clear();
for(int i=0; i<n; i++)
book[s[i]]++;
for(int i=0; i<123; i++)
{
if(book[i]!=0)
{
if(book[i]&1)
{
od.push_back((char)i);
book[i]--;
}
while(book[i])
{
ev.push_back(i);
book[i] -= 2;
}
}
}
char ans
;
int k = 0;
if(od.size()==0)
{
printf("1\n");
for(int i=0; i<n/2; i++)
{
ans[i] = ans[n-1-i] = ev[k++];
}
printf("%s",ans);
cout<<endl;
}
else
{
while(ev.size()%od.size())
{
od.push_back(ev.back());
od.push_back(ev.back());
ev.pop_back();
}
int len = n/od.size();
printf("%d\n", od.size());
for(int i=0;i<od.size();i++)
{
ans[len/2] = od[i];
for(int j=0;j<len/2;j++)
{
ans[j] = ans[len-1-j] = ev[k++];
}
ans[len]='\0';
if(i!=od.size()-1) printf("%s ",ans);
else printf("%s\n", ans);
}
}
4000
return 0;
}
CodeForces - 883I
感觉确实需要搞一下这些DP。。。 要不然真到了题解都看不懂的地步了
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define inf 0x3f3f3f3f #define ms(x) memset(x, 0, sizeof(x)) using namespace std; const int N = 3e5+10; int dp ; int a ; int n, k; int main() { scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) scanf("%d", &a[i]); sort(a+1, a+1+n); int l = -1, r = a -a[1]; while(l<=r) { int mid = (l+r)>>1; int pos = 0, t; for(int i=k;i<=n;i++) { t = dp[i-k]; if(a[i] - a[t+1]<=mid) pos = i; dp[i] = pos; } if(dp == n) r = mid-1; else l = mid+1; } cout<<r+1<<endl; return 0; }
相关文章推荐
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest G. Orientation of Edges
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest K. Road Widening
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Prefer
- codeforces883I 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rule
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Prefer
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest M. Quadcopter Competition
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest F. Lost in Transliteration
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest Union of Doubly Linked Lists
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest H. Palindromic Cut
- M - Quadcopter Competition 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest E. Field of Wonders
- E - Field of Wonders 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Prefer
- codeforces/2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (B)
- 2017-2018 ACM-ICPC, NEERC, Northern Subregional Contest
- Codeforces 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror)
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) J dp 背包