Cinema - CodeForces 670C - Virtual Judge
TAG: map离散化
#include<iostream>
#include<map>
using namespace std;
const int N=2e7+10;
int a[N];
int n,m;
map<int,int> mp;
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
int b;
cin>>b;
mp[b]++;
}
int k,max1=-1,max2=-1;
cin>>m;
for(int i=1;i<=m;i++)
{
cin>>a[i];
max1=max(max1,mp[a[i]]);
}
for(int i=1;i<=m;i++)
{
int b;
cin>>b;
if(mp[a[i]]==max1&&mp[b]>max2)
{
max2=mp[b],k=i;
}
}
cout<<k<<endl;
return 0;
}
Pashmak and Garden - CodeForces 459A - Virtual Judge
TAG:分类讨论
#include<iostream>
using namespace std;
int main()
{
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
if(x1==x2&&y1!=y2)
{
printf("%d %d %d %d\n",x1+y2-y1,y1,x2+y2-y1,y2);
return 0;
}
if(y1==y2&&x1!=x2)
{
printf("%d %d %d %d\n",x1,y1+x2-x1,x2,y2+x2-x1);
return 0;
}
if(abs(x1-x2)==abs(y1-y2)&&y1!=y2)
{
printf("%d %d %d %d\n",x1,y2,x2,y1);
return 0;
}
cout<<-1<<endl;
return 0;
}
Pashmak and Flowers - CodeForces 459B - Virtual Judge
TAG:排序 数学
#include<bits/stdc++.h>
#define x first
#define y second
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(a) cout<<a<<'\n'
#define endl '\n'
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=2e5+10,M=1,inf=0x3f3f3f3f,mod=1e9+7;
LL a[N];
LL n;
int main()
{
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
LL minn=a[0],maxn=a[n-1];
LL ans=maxn-minn;
LL cnt1=0,cnt2=0;
for(int i=0;i<n;i++) if(a[i]==minn) cnt1++;
for(int i=0;i<n;i++) if(a[i]==maxn) cnt2++;
if(minn==maxn) cout<<ans<<" "<<n*(n-1)/2<<endl;
else cout<<ans<<" "<<cnt1*cnt2<<endl;
return 0;
}
Simple Game - CodeForces 570B - Virtual Judge
TAG:数学
#include<iostream>
using namespace std;
typedef long long LL;
const int N=1e5+10;
LL n,m,c;
int main()
{
cin>>n>>m;
if(n==1)
c=1;
else if(2*m>=n+1)
c=m-1;
else c=m+1;
cout<<c<<endl;
return 0;
}
Elections - CodeForces 570A - Virtual Judge