A.统计字母个数。

#include<bits/stdc++.h>
using namespace std; string s;
int n;
map<char,int> mp; int main()
{
ios::sync_with_stdio();
cin >> s >> n;
int cnt = ;
for(int i = ;i < s.length();i++)
{
if(mp[s[i]] == ) cnt++;
mp[s[i]] = ;
}
if(s.length() < n) cout << "impossible" << endl;
else cout << max(,n-cnt) << endl;
return ;
}

B.统计每行每列0和1的个数,各自组合数计算数量,最后吧重复的n*m个减去。

#include<bits/stdc++.h>
using namespace std; int n,m,a[][]; long long c(int x)
{
long long ans = ;
for(int i = ;i <= x;i++) ans *= ;
return ans-;
} int main()
{
ios::sync_with_stdio();
cin >> n >>m;
for(int i = ;i <= n;i++)
{
for(int j = ;j <= m;j++) cin >> a[i][j];
}
long long ans = -n*m;
for(int i = ;i <= n;i++)
{
int cnt = ;
for(int j = ;j <= m;j++)
{
if(a[i][j] == ) cnt++;
}
ans += c(cnt);
ans += c(m-cnt);
}
for(int i = ;i <= m;i++)
{
int cnt = ;
for(int j = ;j <= n;j++)
{
if(a[j][i] == ) cnt++;
}
ans += c(cnt);
ans += c(n-cnt);
}
cout << ans << endl;
return ;
}

C.离散化后,统计环的数量。

#include<bits/stdc++.h>
using namespace std; int n,a[],b[],cnt,vis[] = {};
vector<int> v[],ans[];
map<int,int> mp; void dfs(int x)
{
vis[x] = ;
ans[cnt].push_back(x);
for(int i = ;i < v[x].size();i++)
{
int t = v[x][i];
if(vis[t]) continue;
dfs(t);
}
} int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i],b[i] = a[i];
sort(b+,b++n);
for(int i = ;i <= n;i++) mp[b[i]] = i;
for(int i = ;i <= n;i++)
{
v[i].push_back(mp[a[i]]);
}
cnt = ;
for(int i = ;i <= n;i++)
{
if(!vis[i])
{
cnt++;
dfs(i);
}
}
cout << cnt << endl;
for(int i = ;i <= cnt;i++) sort(ans[i].begin(),ans[i].end());
for(int i = ;i <= cnt;i++)
{
cout << ans[i].size() << " ";
for(int j = ;j < ans[i].size();j++) cout << ans[i][j] << " ";
cout << endl;
}
return ;
}

D.随机1000个点,剩下线性找1000个,有连续1000个点不被随1000次随到的概率可以忽略。

#include<bits/stdc++.h>
using namespace std; int n,now,x;
map<int,int> mp; int main()
{
ios::sync_with_stdio();
srand(time());
cin >> n >> now >> x;
cout << "? " << now << endl;
int ne;
cin >> now >> ne;
if(now >= x)
{
cout << "! " << now << endl;
return ;
}
for(int i = ;i <= ;i++)
{
long long t = (long long)rand()*rand()%n+;
cout << "? " << t << endl;
int v,vv;
cin >> v >> vv;
if(v < x && v > now)
{
now = v;
ne = vv;
}
}
while(ne != -)
{
cout << "? " << ne << endl;
cin >> now >> ne;
if(now >= x)
{
cout << "! " << now << endl;
return ;
}
}
cout << "! -1" << endl;
return ;
}

Codeforces_844的更多相关文章

随机推荐

  1. Java江湖之设计模式

    Java江湖之设计模式 ps:最近在学习设计模式,感觉这个是个装逼神器呀,就跟武功一样.     某日,senior同学看见rookie同学在练功.     问,"你练得什么武功?" ...

  2. Vue.js项目在apache服务器部署后,刷新404的问题

    原因是vue-router 使用了路由的 history 模式,这种模式充分利用 history.pushState API 来完成 URL 跳转而无须重新加载页面. const router = n ...

  3. 每日一问2:堆(heap)和栈(stack)的区别

    因为这里没有明确指出堆是指数据结构还是存储方式,所以两个尝试都回答一下. 一.堆和栈作为数据结构 1.堆(heap),也叫做优先队列(priority queue),队列中允许的操作是先进先出(FIF ...

  4. CTPN中anchors代码

    import numpy as np def generate_basic_anchors(sizes, base_size=16): #base_anchor([0,0,15,15]) base_a ...

  5. 1z0-062 题库解析2

    Examine the parameters for a database instance: NAME TYPE VALUE-------------------------------- ---- ...

  6. 深入理解 CSS(Cascading Style Sheets)中的层叠(Cascading)

    标题中的 Cascading 亦可以理解为级联. 进入正文,这是一个很有意思的现象.可以直接跳到 总结一下 部分,看完再回过头来阅读本文. 引子 假设我们有如下结构: <p class=&quo ...

  7. python命名空间(namespace)

    命名空间: 每一个作用域变量存储的位置,或者解释为 存储作用域中变量的字典. 作用: 获取想查看某个作用域中的变量名.变量值. 使用方法: locals()  #当前命名空间 1. 效果图: 2. 代 ...

  8. 浏览器应用集成嵌入WPS指南

    因为该WPS插件使用NPAPI机制来和浏览器交互,故要求使用插件的浏览器必须支持NPAPI机制且必须开启NPAPI机制. 以下是支持的常见的浏览器及其版本: FireFox浏览器52及小于52的版本( ...

  9. Linux查看端口监听占用

    # 查看所有 netstat -ntlp # 过滤PORT8080 netstat -ntlp | grep 8080 -t # 仅显示tcp相关选项 -u # 仅显示udp相关选项 -n # 拒绝显 ...

  10. 【译】如何使用Vue过渡效果来提升用户体验

    在Vue应用中添加过渡效果是一个可以使你的项目感觉更专业的简单方法.通过提升用户体验,可以使你的网站留住更多的用户以及提高转化率. 只需要简单的处理就可以获得巨大的回报,何乐而不为? 在这个指南中,我 ...