A http://codeforces.com/contest/479/problem/A
枚举情况
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
int a,b,c;
while(~scanf("%d%d%d",&a,&b,&c)){
int ans=;
ans=max(ans,a+b+c);
ans=max(ans,a*b*c);
ans=max(ans,a*b+c);
ans=max(ans,a+b*c);
ans=max(ans,(a+b)*c);
ans=max(ans,a*(b+c));
printf("%d\n",ans);
}
return ;
}
B http://codeforces.com/contest/479/problem/B
暴力,每次拿一个,然后排序。
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int inf=0x3f3f3f3f;
struct G{
int val,id;
friend bool operator <(const G &a,const G &b){
return a.val<b.val;
}
}g[];
struct A{
int x,y;
}now;
vector<A> ans;
int main(){
int n,k;
while(~scanf("%d%d",&n,&k)){
int big=,sma=inf,cha;
for(int i=;i<n;i++){
scanf("%d",&g[i].val);
g[i].id=i+;
big=max(big,g[i].val);
sma=min(sma,g[i].val);
}
cha=big-sma;
ans.clear();
while(k--&&cha){
sort(g,g+n);
g[].val++;
g[n-].val--;
big=;
sma=inf;
for(int i=;i<n;i++){
big=max(big,g[i].val);
sma=min(sma,g[i].val);
}
if(big-sma>cha) break;
cha=big-sma;
now.x=g[n-].id;
now.y=g[].id;
ans.push_back(now);
}
printf("%d %d\n",cha,ans.size());
int len=ans.size();
for(int i=;i<len;i++){
printf("%d %d\n",ans[i].x,ans[i].y);
}
}
return ;
}
c
贪心
#include<cstdio>
#include<algorithm>
using namespace std;
const int M=;
struct G{
int a,b;
friend bool operator <(const G &a,const G &b){
return a.a<b.a;
}
}g[M];
int main(){
int n;
while(~scanf("%d",&n)){
for(int i=;i<n;i++){
scanf("%d%d",&g[i].a,&g[i].b);
}
sort(g,g+n);
int now=;
for(int i=;i<n;){
int s=i,t;
int big=;
int sma=0x3f3f3f3f;
for(int j=i;j<n;j++){
if(g[i].a==g[j].a){
t=j;
big=max(big,g[j].b);
sma=min(sma,g[j].b);
}
else{
break;
}
}
if(big<g[i].a&&sma>=now){
now=big;
}
else{
now=g[i].a;
}
i=t+;
}
printf("%d\n",now);
}
return ;
}
d
map 判断是否存在
#include<cstdio>
#include<map>
using namespace std;
const int M=1e5+;
int a[M];
int l;
map<int,bool> mp;
bool has(int x,int y) {
if(mp[x+y]||mp[x-y]) return true;
return false;
}
bool in(int x) {
if(x>=&&x<=l) return true;
return false;
}
int main() {
int n,x,y;
while(~scanf("%d%d%d%d",&n,&l,&x,&y)) {
mp.clear();
for(int i=; i<n; i++) {
scanf("%d",&a[i]);
mp[a[i]]=true;
}
bool fx=false,fy=false;
for(int i=; i<n; i++) {
if(has(a[i],x)) {
fx=true;
}
if(has(a[i],y)) {
fy=true;
}
}
if(fx&&fy) {
puts("");
continue;
}
if(!fx&&fy) {
puts("");
printf("%d\n",x);
continue;
}
if(fx&&!fy) {
puts("");
printf("%d\n",y);
continue;
}
int ans=-;
for(int i=; i<n; i++) {
if(in(a[i]-x)&&has(a[i]-x,y)) {
ans=a[i]-x;
break;
}
if(in(a[i]+x)&&has(a[i]+x,y)) {
ans=a[i]+x;
break;
}
if(in(a[i]-y)&&has(a[i]-y,x)) {
ans=a[i]-y;
break;
}
if(in(a[i]+y)&&has(a[i]+y,x)) {
ans=a[i]+y;
break;
}
}
if(ans!=-) {
puts("");
printf("%d\n",ans);
} else {
puts("");
printf("%d %d\n",x,y);
}
}
return ;
}
end