Codeforces 999
A
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }};
const int mod = 1e9 + , gakki = + + + + 1e9;
const int MAXN = 2e5 + , MAXM = 2e5 + , N = 2e5 + ;
const int MAXQ = ;
/*int to[MAXM << 1], nxt[MAXM << 1], Head[MAXN], tot = 1;
inline void addedge(int u, int v)
{
to[++tot] = v;
nxt[tot] = Head[u];
Head[u] = tot;
}*/
inline void read(int &v)
{
v = ;
char c = ;
int p = ;
while (c < '' || c > '')
{
if (c == '-')
{
p = -;
}
c = getchar();
}
while (c >= '' && c <= '')
{
v = (v << ) + (v << ) + c - '';
c = getchar();
}
v *= p;
}
int num[];
int visit[];
int main()
{
int n, k;
read(n), read(k);
for (int i = ; i <= n; i++)
{
read(num[i]);
}
int anser = ;
for (int i = ; i <= n; i++)
{
if (num[i] <= k)
{
visit[i] = ;
anser++;
}
else
{
break;
}
}
for (int i = n; i >= ; i--)
{
if (visit[i])
{
break;
}
if (num[i] <= k)
{
anser++;
}
else
{
break;
}
}
cout << anser << endl;
return ;
}
B
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }};
const int mod = 1e9 + , gakki = + + + + 1e9;
const int MAXN = 2e5 + , MAXM = 2e5 + , N = 2e5 + ;
const int MAXQ = ;
/*int to[MAXM << 1], nxt[MAXM << 1], Head[MAXN], tot = 1;
inline void addedge(int u, int v)
{
to[++tot] = v;
nxt[tot] = Head[u];
Head[u] = tot;
}*/
inline void read(int &v)
{
v = ;
char c = ;
int p = ;
while (c < '' || c > '')
{
if (c == '-')
{
p = -;
}
c = getchar();
}
while (c >= '' && c <= '')
{
v = (v << ) + (v << ) + c - '';
c = getchar();
}
v *= p;
}
string s;
void doit(int x)
{
for (int i = ; i <= x / - ; i++)
{
swap(s[i], s[x - - i]);
}
}
int main()
{
int n;
read(n);
cin >> s;
for (int i = ; i <= n; i++)
{
if (n % i == )
{
doit(i);
}
}
cout << s << endl;
return ;
}
C
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }};
const int mod = 1e9 + , gakki = + + + + 1e9;
const int MAXN = 2e5 + , MAXM = 2e5 + , N = 2e5 + ;
const int MAXQ = ;
/*int to[MAXM << 1], nxt[MAXM << 1], Head[MAXN], tot = 1;
inline void addedge(int u, int v)
{
to[++tot] = v;
nxt[tot] = Head[u];
Head[u] = tot;
}*/
inline void read(int &v)
{
v = ;
char c = ;
int p = ;
while (c < '' || c > '')
{
if (c == '-')
{
p = -;
}
c = getchar();
}
while (c >= '' && c <= '')
{
v = (v << ) + (v << ) + c - '';
c = getchar();
}
v *= p;
}
string s;
int visit[];
queue<int> ch[];
int main()
{
int n, k;
read(n), read(k);
cin >> s;
for (int i = ; i < s.size(); i++)
{
ch[s[i] - 'a'].push(i);
//cout<<s[i]-'a'<<" "<<i<<endl;
}
for (int j = ; j <= k; j++)
{
for (int i = ; i <= ; i++)
{
if (ch[i].size() > )
{
visit[ch[i].front()] = ;
ch[i].pop();
break;
}
}
}
for (int i = ; i < s.size(); i++)
{
if(!visit[i])
{
cout<<s[i];
}
}
return ;
}
D
磨了半天 没想到直接暴力也能过
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = ;
int n, m, a[N];
vector<int> c[N];
LL ans;
int main()
{
scanf("%d%d", &n, &m);
for (int i = ; i < n; i++)
{
scanf("%d", &a[i]);
c[a[i] % m].push_back(i);
}
int ptr = ;
int goal = n / m;
for (int i = ; i < m; i++) //从0开始检查比goal大的
{
while ((int)c[i].size() > goal) //如果枚举到的比水平线高
{
ptr = max(ptr, i); //保证找到的要在其后
while ((int)c[ptr % m].size() >= goal) //找到小于水平线的
{
ptr ++;
}
int tk = min((int)c[i].size() - goal, goal - (int)c[ptr % m].size()); //取多出与缺少的最小值
int dlt = ptr - i; //多的和少的之间的距离
while (tk--)
{
ans += dlt;
a[c[i].back()] += dlt;
c[ptr % m].push_back(c[i].back());
c[i].pop_back();
}
}
}
printf("%lld\n", ans);
for (int i = ; i < n; i++)
{
printf("%d%c", a[i], " \n"[i + == n]);
}
}
E
暴力染色即可
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }};
const int mod = 1e9 + , gakki = + + + + 1e9;
const int MAXN = 5e3 + , MAXM = 5e3 + , N = 2e5 + ;
const int MAXQ = ;
int to[MAXM << ], nxt[MAXM << ], Head[MAXN], tot = ;
inline void addedge(int u, int v)
{
to[++tot] = v;
nxt[tot] = Head[u];
Head[u] = tot;
}
inline void read(int &v)
{
v = ;
char c = ;
int p = ;
while (c < '' || c > '')
{
if (c == '-')
{
p = -;
}
c = getchar();
}
while (c >= '' && c <= '')
{
v = (v << ) + (v << ) + c - '';
c = getchar();
}
v *= p;
}
int du[MAXN], visit[MAXN];
int visit2[MAXN];
int ans = ;
void dfs(int x, int pre)
{
visit[x] = pre;
visit2[x] = ;
for (int i = Head[x]; i; i = nxt[i])
{
int v = to[i];
if (!visit2[v])
{
dfs(v, pre);
}
}
}
int vis[MAXN];
int main()
{
int n, m, s, u, v;
read(n), read(m), read(s);
for (int i = ; i <= m; i++)
{
read(u), read(v);
addedge(u, v);
du[v]++;
}
for (int i = ; i <= n; i++)
{
if (!visit[i])
{
mem(visit2, );
dfs(i, i);
}
}
mem(visit2,);
dfs(s, s);
for (int i = ; i <= n; i++)
{
if (vis[visit[i]] == )
{
vis[visit[i]] = ;
ans++;
}
}
cout << ans - << endl;
}
tarjan缩点后找入度为0的点 可以O(n+m)的做
F
dp
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = ;
int n, k, c[N], f[N], h[N];
const int K = ;
int dp[ * K];
int cal(int x)
{
if (f[x] == )
{
return ;
}
int atmst = min(f[x] * k, c[x]);
for (int i = ; i <= atmst; i++)
{
dp[i] = ;
}
while (f[x]--)
{
for (int i = atmst; i >= ; i--)
for (int j = ; j <= k and i - j >= ; j++)
{
dp[i] = max(dp[i], dp[i - j] + h[j]);
}
}
return dp[atmst];
}
int main()
{
scanf("%d%d", &n, &k);
for (int i = ; i < n * k; i++)
{
int ci;
scanf("%d", &ci);
c[ci]++;
}
for (int i = ; i < n; i++)
{
int fi;
scanf("%d", &fi);
f[fi]++;
}
for (int i = ; i <= k; i++)
{
scanf("%d", &h[i]);
}
int ans = ;
for (int i = ; i < N; i++)
{
ans += cal(i);
}
cout << ans << endl;
}
Codeforces 999的更多相关文章
- codeforces#999 E. Reachability from the Capital(图论加边)
题目链接: https://codeforces.com/contest/999/problem/E 题意: 在有向图中加边,让$S$点可以到达所有点 数据范围: $ 1 \leq n \leq 50 ...
- CodeForces 219B Special Offer! Super Price 999 Bourles!
Special Offer! Super Price 999 Bourles! Time Limit:1000MS Memory Limit:262144KB 64bit IO For ...
- 构造 Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!
题目传送门 /* 构造:从大到小构造,每一次都把最后不是9的变为9,p - p MOD 10^k - 1,直到小于最小值. 另外,最多len-1次循环 */ #include <cstdio&g ...
- 【模拟】NEERC15 J Jump(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
题目链接: http://codeforces.com/gym/100851 题目大意: 系统里生成一个字符串C,一开始告诉你字符串的长度N(偶数).接着你需要在n+500次内猜出这个字符串是什么. ...
- Codeforces Round #425 (Div. 2)C
题目连接:http://codeforces.com/contest/832/problem/C C. Strange Radiation time limit per test 3 seconds ...
- Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)
A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- Codeforces Round #520
占个坑慢慢填 A ()[http://codeforces.com/contest/1062/problem/A] 题意:现在有一个长度为n的严格上升正整数序列 每个数的取值在[1, 1000] 现在 ...
- Codeforces 999F Cards and Joy(二维DP)
题目链接:http://codeforces.com/problemset/problem/999/F 题目大意:有n个人,n*k张卡牌,每个人会发到k张卡牌,每个人都有一种喜欢的卡牌f[i],当一个 ...
- Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论
n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...
随机推荐
- Linux安装Vmware Tools/vmtools(通用)
以下方法适用于centos/Ubuntu #新建一个临时目录,用于挂载光驱 mkdir /tmp/cdrom mount -t iso9660 /dev/cdrom /tmp/cdrom cp -r ...
- HTML <canvas> 学习笔记
Professional JavaScript for Web Developers P552 Basic Usage The <canvas> element requires a ...
- Intervals and Timeouts
Intervals var num = 0; var max = 10; function incrementNumber(){ num++; // if the max has not been r ...
- Python flask 与 GO WEB服务器性能对比
测试环境: 系统: CentOS 7.1 Mem: 8G CPU: 虚拟机16核 Python版本: python3.6 Flask版本: 0.12.2 Golang版本: 1.6.3 1.首先写一个 ...
- go语言20小时从入门到精通(六、工程管理)
在实际的开发工作中,直接调用编译器进行编译和链接的场景是少而又少,因为在工程中不会简单到只有一个源代码文件,且源文件之间会有相互的依赖关系.如果这样一个文件一个文件逐步编译,那不亚于一场灾难. Go语 ...
- 【HANA系列】【第四篇】SAP HANA XS使用服务器JavaScript Libraries详解
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列][第四篇]SAP HANA XS ...
- Git-T
或在命令行上创建一个新的存储库echo“#gittest”>> README.md git init git add README.md git commit -m“first commi ...
- python高级 之(五) --- 文件操作
文件操作 """ 在程序中操作的文件内容: 1. 读取文件中的内容 2. 向文件中写入内容 首先: 在程序中与文件建立一个通道,通过通道操作文件指针,达到所要的结果 向文 ...
- Java 虚拟机的运行模式
这几天在读周志明老师的<深入理解JVM虚拟机> 讲到了 java的运行模式, 有mixed 模式 interpret模式还有compile模式.效果如下面所示 java -version ...
- 【转帖】GBase 数据库
产品介绍 分析型数据管理系统 GBase 8a GBase 8a能够实现大数据的全数据(结构化数据.半结构化数据和非结构化数据)存储管理和高效分析,为行业大数据应用提供完整的数据库解决方案.GBase ...