题意:给你一些数字,看能否全部均等的分成两部分,可以的话输出每对的编号,不行的话输出-1
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stack>
using namespace std;
int a;
stack<int>p[5001];
int main()
{
int n;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%d",&n);
for(int i=1;i<=5000;i++)
{
while(p[i].size())
p[i].pop();
}
for(int i=1;i<=2*n;i++)
{
scanf("%d",&a);
p[a].push(i);
}
for(int i=1;i<=5000;i++)
{
if(p[i].size()%2==1)
{
printf("-1\n");
return 0;
}
}
for(int i=1;i<=5000;i++)
{
while(p[i].size())
{
int e=p[i].top();
p[i].pop();
int f=p[i].top();
p[i].pop();
printf("%d %d\n",e,f);
}
}
return 0;
}
题意:染色问题,求被覆盖区间内的最大值,可能会到2012年,做复杂了。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int a[366];
int b[367];
int m,d,r,t;
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int dd(int m,int d)
{
int ans=0;
for(int i=0;i<m;i++)
{
ans+=month[i];
}
ans+=d;
return ans;
}
int main()
{
int cases;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%d",&cases);
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(int i=1;i<=cases;i++)
{//9.3 9.8 6day 12.9
scanf("%d%d%d%d",&m,&d,&r,&t);
int today=dd(m,d);
int tag=0;
if(today<=t)
{
//printf("nimei\n");
tag=1;
t=t-today;
}
if(tag)
{
for(int i=366;i>=366-t;i--)
{
b[i]+=r;
}
for(int i=1;i<=today-1;i++)
a[i]+=r;
}
else
for(int i=today-t;i<=today-1;i++)
{
a[i]+=r;
}
}
int ans=0;
for(int i=0;i<=365;i++)
{
ans=max(ans,a[i]);
}
for(int i=0;i<=366;i++)
{
ans=max(ans,b[i]);
}
//printf("b[366]=%d\n",b[366]);
//printf("a[1]=%d\n",a[1]);
printf("%d\n",ans);
return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
string s1,s2;
int a[26];
int b[26];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin>>s1>>s2;
for(int i=0;i<s1.size();i++)
a[s1[i]-'A']++;
for(int i=0;i<s2.size();i++)
b[s2[i]-'A']++;
string s;
for(int i=0;i<26;i++)
{
int mm=b[i]-a[i];
if(mm>=0)
s+=string(mm,i+'A');
a[i]-=b[i];
}
cout<<s.size()<<endl;
int tt=0;
for(int i=0;i<s1.size();i++)
{
if(a[s1[i]-'A']>0)
{
if(s1[i]>s[tt])
{
a[s1[i]-'A']--;
s1[i]=s[tt];
tt++;
}
else
{
if(b[s1[i]-'A']>0)
b[s1[i]-'A']--;
else
{
a[s1[i]-'A']--;
s1[i]=s[tt];
tt++;
}
}
}
}
cout<<s1<<endl;
return 0;
}