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 ...
随机推荐
- 2. Java中的垃圾收集 - GC参考手册
标记-清除(Mark and Sweep)是最经典的垃圾收集算法.将理论用于生产实践时, 会有很多需要优化调整的地点, 以适应具体环境.下面通过一个简单的例子, 让我们一步步记录下来, 看看如何才能保 ...
- 第二十节:Scrapy爬虫框架之使用Pipeline存储
在上两节当中,我们爬取了360图片,但是我们需要将图片下载下来,这将如何下载和存储呢? 下边叙述一下三种情况:1.将图片下载后存储到MongoDB数据库:2.将图片下载后存储在MySQL数据库:3.将 ...
- allegro学习--区域约束
前言: 在有些情况需要我们在走线时在某些区域的时候,线是细的,例如BGA封装的FPGA在引出线的时候,我们希望在FPGA内部的线细,出了FPGA后,线变粗.如图: 这就用到了区域的规则约束. 实现: ...
- chrome webstore
chrome webstore https://chrome.google.com/webstore/detail/set-character-encoding/bpojelgakakmcfmjfil ...
- Python模块:shutil、序列化(json&pickle&shelve)、xml
shutil模块: 高级的 文件.文件夹.压缩包 处理模块 shutil.copyfileobj(fscr,fdst [, length]) # 将文件内容拷贝到另一个文件中 import shu ...
- codevs 3971 航班
题目描述 Description B 国有N 座城市,其中1 号是这座国家的首都. N 座城市之间有M 趟双向航班.i 号点的转机次数定义为:从1 号点到i ,最少需要转机几 次.如果1 根本无法到达 ...
- SQL SERVER 2012 第三章 T-SQL 基本语句 group by 聚合函数
select Name,salesPersonID From Sales.store where name between 'g' and 'j' and salespersonID > 283 ...
- UVA 10564_ Paths through the Hourglass
题意: 由0-9的数字组成一个形如沙漏的图形,要求从第一行开始沿左下或者右下到达最后一行,问有多少种不同的路径,使最后路径上的整数之和为给定的某个数. 分析: 简单计数dp,从最后一行开始,设dp[i ...
- MongoDB小结02 - 配置、启动MongoDB
下载MongoDB 第一步:登上MongoDB官网,找到自己的适合的版本下载 第二步:解压(免安装),改名mongodb(举例命名,可以任个人喜好),放在你喜欢的位置(任喜好) 第三步:通过命令行: ...
- openstack setup demo Image service
Image service (glance)是openstack中管理vm image的service.本文包含以下内容: overview install overview glance包含以下部分 ...