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 ... 
随机推荐
- Spring MVC整合fastjson、EasyUI乱码问题
			一.框架版本 Spring MVC:spring-webmvc-4.0.0.RELEASE fastjson:fastjson-1.2.45 EasyUI:1.5 二.乱码现象 Controller调 ... 
- Xcode里如何修改类的名字
			今天有朋友问我他的AFNetWorking和别的文件冲突啦,于是我帮他测试了下: 传送门: http://jingyan.baidu.com/article/fb48e8be35726f6e622e1 ... 
- cmake生成Makefile时指定c/c++编译器
			cmake .. -DCMAKE_CXX_COMPILER:FILEPATH=/usr/local/bin/g++ -DCMAKE_C_COMPILER:FILEPATH=/usr/local/bin ... 
- java中instanceof的基本使用
			java中的instanceof运算符是用于判断对象是否是指定类或这个指定类的子类的一个实例,返回值是布尔类型. 语法: boolean result = object instanceof clas ... 
- HBITMAP与BITMAP 的区别
			HBITMAP 是句柄: BITMAP 是实例: typedef struct tagBITMAP { LONG bmType; ... 
- 【Python开发】python读写文件,和设置文件的字符编码比如utf-8
			一. python打开文件代码如下: f = open("d:\test.txt", "w") 说明: 第一个参数是文件名称,包括路径: 第二个参数是打开的模式 ... 
- elk logstash Managing Multiline Events
			1.Java程序的日志特征,logstash 正为此准备好了 codec/multiline 插件! 有时候应用程序会抛异常,就存在着如何合并多行信息的问题,我这里做的配置就是如果当前行是以‘空格’, ... 
- Linux 目录与路径
			树形目录结构 Linux 是以树形目录结构的形式来构建整个系统的. 从逻辑上来说Linux的磁盘是挂载在目录上的,每一个目录能使用本地磁盘分区或网络上的文件系统,比如利用网络文件系统(Network ... 
- [xpath] 定位中starts-with、contains和text()的用法
			starts-with 顾名思义,匹配一个属性开始位置的关键字 contains 匹配一个属性值中包含的字符串 text() 匹配的是显示文本信息,此处也可以用来做定位用 eg //input[sta ... 
- Redis数据库连接
			1.建立maven项目pox.xml导入依赖包 <dependency> <groupId>io.lettuce</groupId> <artifactId& ... 
