codeforces #332 div2
A.
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
#include<string>
using namespace std;
int a,b,c;
int ans1,ans2,ans3;
int main()
{
//freopen("input.txt","r",stdin);
cin>>a>>b>>c;
int ans1=2*(a+b);
int ans2=2*(a+c);
int ans3=2*(b+c);
int ans4=a+b+c;
int w=min(min(ans1,ans2),min(ans3,ans4));
cout<<w<<endl;
}
B.
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
#include<string>
using namespace std;
int n,m;
int ans[100005];
int w[100005];
map<int,int> q;
map<int,int>::iterator it;
int flag=2;
int main()
{
// freopen("input.txt","r",stdin);
int t;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%d",&t);
q.insert(pair<int,int>(t,i+1));
ans[t]++;
}
for(int i=0;i<m;i++)
{
scanf("%d",&t);
it=q.find(t);
if(it!=q.end()&&flag!=1)
{
w[i]=it -> second;
if(ans[it->first]>1)
flag=0;
}
else
flag=1;
}
if(flag==1)
printf("Impossible\n");
else if(flag==0)
printf("Ambiguity\n");
else
{
printf("Possible\n");
for(int i=0;i<m;i++)
printf("%d ",w[i]);
}
}
C.
贪心:前缀最大值不大于后缀最小值
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<iostream>
#include<cstring>
using namespace std;
int a[100005];
int ma[100005];
int mi[100005];
int main()
{
int n,ans=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
ma[0]=-1;
for(int i=1;i<=n;i++)
{
ma[i]=max(ma[i-1],a[i]);
}
mi[n+1]=1e9+5;
mi[n]=a[n];
for(int i=n-1;i>=1;i--)
{
mi[i]=min(mi[i+1],a[i]);
}
for(int i=1;i<=n;i++)
{
if(ma[i]<=mi[i+1])
ans++;
}
printf("%d\n",ans);
}
D.数学题
f(n,m)=∑k=(n−k+1)(m−k+1)
f(n,m)=(n*n/2+n/2)m+n*n+n−(n+2)(n+1)n/2+n(n+1)(2*n+1)/6
枚举n
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> p;
long long n;
long long ans,x,y;
vector<p>t; int main()
{
scanf("%I64d",&n);
int xx=6*pow(n,1.0/3.0);
// printf("%d\n",xx);
for(long long i=1;i<=xx;i++)
{
x=(i*i+i)/2;
y=n-i*i-i+(i+2)*(i+1)*i/2-(i+1)*i*(2*i+1)/6;
if(y>0&&y%x==0)
{
ans++;
long long dd=y/x;
if(dd>=i){
t.push_back(make_pair<LL,LL>(i,dd));
t.push_back(make_pair<LL,LL>(dd,i));
}
}
}
sort(t.begin(),t.end());
int len=unique(t.begin(),t.end())-t.begin();
printf("%d\n",len);
for(int i=0;i<len;i++)
{
printf("%I64d %I64d\n",t[i].first,t[i].second);
}
}
codeforces #332 div2的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- codeforces #332 div 2 D. Spongebob and Squares
http://codeforces.com/contest/599/problem/D 题意:给出总的方格数x,问有多少种不同尺寸的矩形满足题意,输出方案数和长宽(3,5和5,3算两种) 思路:比赛的 ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
随机推荐
- .Net Memory -- Windbg基本命令
命令 解释 .cls 清空命令窗口屏幕 .load dllfullpath 加载debugger扩展dll如SOS sosex psscor. .loadby dll moduleName 加载deb ...
- php对数组中指定键值排序
function array_sort($arr,$keys,$type='asc'){ $keysvalue = $new_array = array(); foreach ($arr as $k= ...
- 查文件大小列表 MySQL问题
du -sh /* | sort -nr 打开网站发现Too many connections The server quit without updating PID file (/usr/loca ...
- Joomla 二次开发 学习笔记
Joomla目录结构 /administrator 管理后台的路径 /cache 是缓存目录 /components 是组件(component)目录 /includes 是一个重要的目录,里面都是J ...
- LeetCode_Integer to Roman
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
- 线程池 异步I/O线程 <第三篇>
在学习异步之前先来说说异步的好处,例如对于不需要CPU参数的输入输出操作,可以将实际的处理步骤分为以下三步: 启动处理: 实际的处理,此时不需要CPU参数: 任务完成后的处理: 以上步骤如果仅仅使用一 ...
- 国际化标签 <fmt:bundle>&<fmt:message>的使用
国际化标签 <fmt:bundle>&<fmt:message>的使用 Message.properties文件: name=www.gis520.com #info= ...
- C语言随笔_fopen
有同学问我,以下代码会输出“===”,为什么呀? if( (fp = fopen("data.dat","r"))==NULL){ printf("= ...
- struct内存对齐
内存对齐其实是为了在程序运行的时候更快的查找内存而做的一种编译器优化. 我们先看这样一个例子: #include <iostream> using namespace std; struc ...
- ALSA音频工具amixer,aplay,arecord
ALSA音频工具编译安装 ========================================================================1.官网http://www. ...