codeforces AIM Tech Round 4 div 2
A:开个桶统计一下,但是不要忘记k和0比较大小
#include<bits/stdc++.h>
using namespace std;
char s[];
int cnt[];
int main()
{
int k;
scanf("%s%d", s, &k);
int n = strlen(s);
if(n < k)
{
puts("impossible");
return ;
}
for(int i = ; i < n; ++i)
{
int t = s[i] - 'a';
++cnt[t];
if(cnt[t] == ) --k;
}
printf("%d\n", max(k, ));
return ;
}
B:很明显只能在同一行同一列,所以一行一列的方案数就是power(2,cnt)-1,减去空集的情况,但是这样每个元素会算重一次,所以要减去n*m
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int n, m;
long long ans = ;
int Map[N][N], row[N][N], col[N][N];
long long power(long long x, long long t)
{
long long ret = ;
for(; t; t >>= , x = x * x) if(t & ) ret = ret * x;
return ret;
}
int main()
{
scanf("%d%d", &n, &m);
for(int i = ; i <= n; ++i)
for(int j = ; j <= m; ++j)
{
scanf("%d", &Map[i][j]);
++row[i][Map[i][j]];
++col[j][Map[i][j]];
}
for(int i = ; i <= n; ++i) ans += power(2ll, row[i][]) + power(2ll, row[i][]) - ;
for(int i = ; i <= m; ++i) ans += power(2ll, col[i][]) + power(2ll, col[i][]) - ;
printf("%I64d\n", ans - (long long)n * (long long)m);
return ;
}
C:一个元素必须回到自己排名对应的位置,所以必然和自己对应位置上的元素连接,然后就和对应位置的元素用并查集连接,最后统计一下就行了
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int n, ans;
int fa[N], a[N];
vector<int> v, vt[N];
inline int find(int x)
{
return x == fa[x] ? x : fa[x] = find(fa[x]);
}
int main()
{
scanf("%d", &n);
ans = n;
for(int i = ; i <= n; ++i)
{
scanf("%d", &a[i]);
v.push_back(a[i]);
}
sort(v.begin(), v.end());
for(int i = ; i <= n; ++i)
{
a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + ;
fa[i] = i;
}
for(int i = ; i <= n; ++i)
{
int x = find(a[a[i]]), y = find(a[i]);
if(x != y)
{
fa[find(a[i])] = x;
--ans;
}
}
for(int i = ; i <= n; ++i) vt[find(a[i])].push_back(i);
printf("%d\n", ans);
for(int i = ; i <= n; ++i)
{
int sz = vt[i].size();
if(sz == ) continue;
printf("%d ", sz);
for(int j = ; j < sz; ++j) printf("%d ", vt[i][j]);
puts("");
}
return ;
}
D:随机化 考这种东西干什么 具体是先随机1000次,然后更新ans,同时记录找到的比x小的最大的数的位置,如果没有就从start更新,然后暴力向后枚举就行了
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int n, start, x, cnt, ans, key, nxt;
vector<int> v;
int vis[N];
int main()
{
srand( + time());
scanf("%d%d%d", &n, &start, &x);
ans = ;
v.push_back(start);
int size = sqrt(n);
for(int i = ; i <= n; ++i) v.push_back(i);
random_shuffle(v.begin(), v.end());
random_shuffle(v.begin(), v.end());
random_shuffle(v.begin(), v.end());
int i = ;
while(i < v.size())
{
if(vis[v[i]])
{
++i;
continue;
}
++cnt;
if(cnt == )
{
printf("! %d\n", ans);
fflush(stdout);
exit();
}
printf("? %d\n", v[i]);
fflush(stdout);
scanf("%d%d", &key, &nxt);
if(key == x)
{
printf("! %d\n", x);
fflush(stdout);
exit();
}
if(nxt == -)
{
++i;
continue;
}
if(key < x)
{
vis[nxt] = ;
++i;
continue;
}
if(key > x)
{
vis[nxt] = ;
++i;
ans = min(ans, key);
}
}
printf("! %d\n", ans);
fflush(stdout);
return ;
}
感觉这个D题很无聊...
codeforces AIM Tech Round 4 div 2的更多相关文章
- 【Codeforces AIM Tech Round 4 (Div. 2) C】
·将排序限制于子序列中,又可以说明什么呢? C. Sorting by Subsequences ·英文题,述大意: 输入一个长度为n的无重复元素的序列{a1,a2……an}(1<= ...
- codeforce AIM tech Round 4 div 2 B rectangles
2017-08-25 15:32:14 writer:pprp 题目: B. Rectangles time limit per test 1 second memory limit per test ...
- Codeforces AIM Tech Round (Div. 2)
这是我第一次完整地参加codeforces的比赛! 成绩 news standings中第50. 我觉这个成绩不太好.我前半小时就过了前三题,但后面的两题不难,却乱搞了1.5h都没有什么结果,然后在等 ...
- AIM Tech Round 3 (Div. 2) (B C D E) (codeforces 709B 709C 709D 709E)
rating又掉下去了.好不容易蓝了.... A..没读懂题,wa了好几次,明天问队友补上... B. Checkpoints 题意:一条直线上n个点x1,x2...xn,现在在位置a,求要经过任意n ...
- Codeforces AIM Tech Round 5 (rated, Div. 1 + Div. 2)
A. Find Square time limit per test: 1 second memory limit per test: 256 megabytes input: standard in ...
- AIM Tech Round 3 (Div. 2) B 数学+贪心
http://codeforces.com/contest/709 题目大意:给一个一维的坐标轴,上面有n个点,我们刚开始在位置a,问,从a点开始走,走n-1个点所需要的最小路程. 思路:我们知道,如 ...
- AIM Tech Round 4 (Div. 2)(A,暴力,B,组合数,C,STL+排序)
A. Diversity time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- AIM Tech Round 3 (Div. 1) B. Recover the String 构造
B. Recover the String 题目连接: http://www.codeforces.com/contest/708/problem/B Description For each str ...
- AIM Tech Round 3 (Div. 1) A. Letters Cyclic Shift 贪心
A. Letters Cyclic Shift 题目连接: http://www.codeforces.com/contest/708/problem/A Description You are gi ...
随机推荐
- SQLAlchmy模块详解
之前写过一篇博客介绍过sqlalchemy的基本用法,本篇博客主要介绍除增删改查以外SQLAlchemy对数据库表的操作,主要内容有单表操作.一对多操作.多对多操作. 一.单表操作 单表操作的增删改查 ...
- 技能CD 效果 shader
技能CD特效 这个效果主要是利用反正切函数完成.atan2(x,y)的返回值是[-PI,PI],这个支持4个象限的反正切函数.关于圆角计算,在上篇文章中有介绍. 现在,我们来看看反正切函数的效果: 在 ...
- Django——配置服务器上线
使用UWSGI和NGINX配置项目上线 首先你得有一个拿得出手的项目 其次,购买了域名,也备案成功了 将settings.py中的DEBUG设置为False 配置Uwsgi 在项目(哪里都可以)中创建 ...
- python接口自动化测试(一)
本节开始,开始介绍python的接口自动化测试,首先需要搭建python开发环境,到https://www.python.org/下载python 版本直接安装就以了,建议 下载python2.7.1 ...
- 九度oj 题目1180:对称矩阵
题目1180:对称矩阵 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3092 解决:1607 题目描述: 输入一个N维矩阵,判断是否对称. 输入: 输入第一行包括一个数:N(1<= ...
- springboot 集成日志 yml配置
原文:https://www.cnblogs.com/bigben0123/p/7895696.html
- 587. Erect the Fence
Problem statement: There are some trees, where each tree is represented by (x,y) coordinate in a two ...
- Multiprocessing system employing pending tags to maintain cache coherence
A pending tag system and method to maintain data coherence in a processing node during pending trans ...
- poj_3006_Dirichlet's Theorem on Arithmetic Progressions_201407041030
Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- Java面试题解析(一)
本文是面试题目系列的第一篇,题目主要来自 GitChat 上一个课程,在此特别记录自身想的答案和在网上查询的结果,分享出来,大家共同学习.如果有不对的地方,欢迎大家指出. Java基础 JDK 和 J ...