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 ...
随机推荐
- @synthesize
@synthesize 相当于把属性当成成员变量来用,不用再写self.属性@synthesize myButton; 这样写了之后,那么编译器会自动生成myButton的实例变量,以及相应的gett ...
- struts 学习之问一
今天在进行struts全局类型和局部类型转换时,发现一个问题,如下: 当输入一个点的坐标时,我使用全局转换提示错误,找不到类,当改变成局部类型转换时,可以成功转换,不知道这个是什么原因,难道全局不可以 ...
- 浅析Struts1和Struts2的Action线程安全问题
tomcat容器对servlet的实现采用的是单例模式,对于一个servlet类,永远只有一个servlet对象存在. 下面我们来解释为什么Struts1是线程不安全的. 1.Struts1 Stru ...
- 使用meta来控制浏览器的渲染方式
<meta name="renderer" content="webkit"><!--默认使用webkit内核(360急速模式)--> ...
- Oracle select 中case 的使用以及使用decode替换case
表结构如下: 将money<50的显示为贫农,money<80的显示为中农,其他的显示为富农,sql 语句如下 select name, case then '贫农' then '中农' ...
- javascript之对象
一.创建对象 1.对象直接量. var point = { x:0,y:0 }; //point就是一个对象,跟C#不同,它不需要一定有类才能创建对象. 2.通过new创建对象 var d = new ...
- HtmlAttribute HTML属性处理类
HtmlAttribute 在HtmlAgilityPack扮演的是一个HTML代码属性的容器,同时提供了用于处理HTML属性的一些功能. 一.属性 int Line { get; } 获取文档中的此 ...
- Asp.net 处理程序(第五篇)
HttpApplication有19个标准事件,当到达第8个事件PostMapRequestHandler触发的时候,标志着已经获取到了处理请求的处理程序对象,在第11个事件PreRequestHan ...
- HTTP协议及HTTP包
HTTP协议用于在Internet上发送和接收消息.HTTP协议是一种请求-应答式的协议 ——客户端发送一个请求,服务器返回该请求的应答,所有的请求与应答都是HTTP包.HTTP协议使用可靠的TCP连 ...
- 关于#ifndef,#define,#end的说明
#ifndef,#define,#end 是宏定义的一种---条件编译 这样我直接举个例子好了:我定义两个相同的类A分别在single.h和singlenew.h single.h: #include ...