Codeforces_844
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的更多相关文章
随机推荐
- npm install 不更改 package-lock.json 文件的解决方法
package-lock.json 文件是版本锁定文件 package-lock.json 是在 `npm install` 时候生成的一份文件,用以记录当前状态下实际安装的各个 npm packag ...
- nodeJS实现识别验证码(tesseract-ocr+GraphicsMagick)
背景 最近在写一个爬虫的小工具,卡在登录这里. 想爬的网站需要登录才能获取数据,登录又需要输入验证码. 好在验证码是简单的验证码,还可以自己识别试试. 需求分析 1.保存验证码图片 2.识别验证码 3 ...
- vmware workstation12在安装VMware tools时出现问题:A previous installation of VMware Tools has been detected 解决
win10安装的vmware workstation12在安装VMware tools时出现问题: root@lc:/root/vmware-tools-distrib# ./vmware-insta ...
- 【记】创建 VirtualBoxClient COM 对象失败. 应用程序将被中断
1. 在本地64位win7系统安装VirtualBox完,启动时提示错误 原因:兼容性造成的 按照下图显示修改VirtualBox快捷方式的兼容性 2. 启动虚拟机时,提示 点击弹出框的确定按钮后,接 ...
- 1z0-062 题库解析2
Examine the parameters for a database instance: NAME TYPE VALUE-------------------------------- ---- ...
- 如何获取scrimba内部(内联框架)中网页地址?
看图: 将其在新窗口打开 方法一:按下F12 键 (打开 开发者工具) ,再照图中箭头用鼠标点击所示, 图中粗红下划线为该页面的URL 地址, 复制在新窗口打开即可 方法二:利用JS代码手动获取 ...
- 定时器之Quart.net(1)
第一步:Install-Package Quartz namespace ProjectEdb { class Program { static void Main(string[] args) { ...
- Prop验证、inheritAttrs、$attrs的用法和坑
Prop Prop验证 Vue.component('my-component', { props: { // 基础的类型检查 (`null` 和 `undefined` 会通过任何类型验证) pro ...
- Creating Custom Helper Methods 创建自定义辅助器方法----辅助器方法 ------ 精通ASP.NET MVC 5
创建内联的辅助器方法 和 拓展方法 好像类似的功能. 不过写在前台更直观
- 为磁盘文件定义路由(Defining Routes for Disk Files) |对磁盘文件进行路由请求 |