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的更多相关文章

  1. 【Codeforces AIM Tech Round 4 (Div. 2) C】

    ·将排序限制于子序列中,又可以说明什么呢? C. Sorting by Subsequences ·英文题,述大意:       输入一个长度为n的无重复元素的序列{a1,a2……an}(1<= ...

  2. 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 ...

  3. Codeforces AIM Tech Round (Div. 2)

    这是我第一次完整地参加codeforces的比赛! 成绩 news standings中第50. 我觉这个成绩不太好.我前半小时就过了前三题,但后面的两题不难,却乱搞了1.5h都没有什么结果,然后在等 ...

  4. 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 ...

  5. 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 ...

  6. AIM Tech Round 3 (Div. 2) B 数学+贪心

    http://codeforces.com/contest/709 题目大意:给一个一维的坐标轴,上面有n个点,我们刚开始在位置a,问,从a点开始走,走n-1个点所需要的最小路程. 思路:我们知道,如 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. ubuntu 16.4 安装mysql-python

    sudo apt-get install python-pip python-dev libmysqlclient-dev pip install MySQL-python

  2. python中基于tcp协议的通信(数据传输)

    tcp协议:流式协议(以数据流的形式通信传输).安全协议(收发信息都需收到确认信息才能完成收发,是一种双向通道的通信) tcp协议在OSI七层协议中属于传输层,它上承用户层的数据收发,下启网络层.数据 ...

  3. hadoop_exporter+prometheus

    1.准备工作 安装go.glibe(需要连google服务器,咋连的,我就不写了,因为尝试了各种办法,都失败了,很伤心) 2.下载hadoop_exporter cd /usr/local/prom/ ...

  4. jar项目 BeanDefinitionParsingException: Configuration problem:Unable to locate Spring NamespaceHandler for XML schema namespace

    最近由于项目需要,需要jar项目来处理. 我在项目中整合了Spring,在编辑器中启动没有问题,但是使用ant打包为一个完整jar文件,部署后启动报错如下 org.springframework.be ...

  5. mvc 下 使用kindeditor 配置信息

    先去下载: http://code.google.com/p/kindeditor/downloads/list引用: LitJSON.dll文件<script src="~/kind ...

  6. Archive log restore using RMAN for Logminer (http://www.dba-village.com/village/dvp_forum.OpenThread?ThreadIdA=26816)

    Subject: Archive log restore using RMAN for Logminer Author: Edwin Weele van der, Netherlands Date: ...

  7. 【状压+状态转移】A Famous Airport Managere

    https://www.bnuoj.com/v3/problem_show.php?pid=25653 [题意] 给定一个3*3的九宫格,模拟一个停机坪.第一个格子一定是'*',代表take off ...

  8. Eclipse配置SVN的几种方法及使用详情

    此文章对Myeclipse同样适用. 一.在Eclipse里下载Subclipse插件 方法一:从Eclipse Marketplace里面下载 具体操作:打开Eclipse --> Help ...

  9. 【HDOJ6118】度度熊的交易计划(费用流)

    题意: 度度熊参与了喵哈哈村的商业大会,但是这次商业大会遇到了一个难题: 喵哈哈村以及周围的村庄可以看做是一共由n个片区,m条公路组成的地区. 由于生产能力的区别,第i个片区能够花费a[i]元生产1个 ...

  10. Servlet CDI 例子分析

    @WebServlet("/cdiservlet") //以@WebServlet注释开头,注释指定相对于上下文根的URL模式,即在根目录下使用/cdiservlet来访问 pub ...