1009 Calabash and Landlord (几何)
题意
在二维平面画两个矩形 问画完之后整个平面有多少个矩形 (本身也算一个)
思路
枚举所有答案
代码
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+100;
typedef long long ll;
int x1,x2,y1,y2;
int x3,x4,y3,y4;
int f;
int minx1,miny1,maxx1,maxy1;
int minx2,miny2,maxx2,maxy2;
void ok2()
{
if(minx1==minx2&&miny1==miny2&&maxx1==maxx2&&maxy1==maxy2){
cout<<"2"<<endl;f = 1;return ;
}
}
void ok3()
{
if(maxx1 <= minx2){
cout<<"3"<<endl;f=1;return ;
}
if(maxy1 <= miny2){
cout<<"3"<<endl;f=1;return ;
}
if(minx1<=minx2 && maxx1>=maxx2 && miny1<=miny2 && maxy1>=maxy2){
int num = 0;
if(minx1==minx2) num++;
if(maxx1==maxx2) num++;
if(miny1==miny2) num++;
if(maxy1==maxy2) num++;
if(num == 2){
if(minx1==minx2&&maxx1==maxx2) return ;
if(miny1==miny2&&maxy1==maxy2) return ;
}
cout<<"3"<<endl;f=1;return ;
}
}
void ok5()
{
if(minx1<minx2 && maxx1>maxx2){
if(maxy1==maxy2&&miny1>miny2){
cout<<"5"<<endl;f=1;return ;
}
if(miny1==miny2&&maxy1<maxy2){
cout<<"5"<<endl;f=1;return ;
}
}
if(miny1<miny2&&maxy1>maxy2){
if(minx1==minx2&&maxx1<maxx2){
cout<<"5"<<endl;f=1;return ;
}
if(maxx1==maxx2&&minx1>minx2){
cout<<"5"<<endl;f=1;return ;
}
}
}
void ok6()
{
if(minx1<minx2&&maxx1>maxx2&&miny1>miny2&&maxy1<maxy2){
cout<<"6"<<endl;f=1;return ;
}
}
int main()
{
ios::sync_with_stdio(false);
int T;
cin>>T;
while(T--)
{
f = 0;
cin>>x1>>y1>>x2>>y2;
minx1 = min(x1,x2),miny1 = min(y1,y2);
maxx1 = max(x1,x2),maxy1 = max(y1,y2);
cin>>x1>>y1>>x2>>y2;
minx2 = min(x1,x2),miny2 = min(y1,y2);
maxx2 = max(x1,x2),maxy2 = max(y1,y2);
ok2();
if(f) continue;
ok3();
if(f) continue;
ok5();
if(f) continue;
ok6();
if(f) continue;
swap(minx1,minx2),swap(maxx1,maxx2);
swap(miny1,miny2),swap(maxy1,maxy2);
ok2();
if(f) continue;
ok3();
if(f) continue;
ok5();
if(f) continue;
ok6();
if(f) continue;
cout<<"4"<<endl;
}
return 0;
}
1010 Quailty and CCPC
http://acm.hdu.edu.cn/showproblem.php?pid=6666
题意
签到题
队友代码
#include <bits/stdc++.h>
using namespace std;
struct code
{
char s[105];
int x,y;
} edge[100005];
int n,t,k;
bool cmp(code a,code b)
{
if(a.x!=b.x)
return a.x>b.x;
else
return a.y<b.y;
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k);
for(int i=1; i<=n; i++)
scanf("%s%d%d",edge[i].s,&edge[i].x,&edge[i].y);
sort(edge+1,edge+1+n,cmp);
k*=n;
if(k%10!=5)
printf("Quailty is very great\n");
else
{
k=k/10;
k++;
printf("%s\n",edge[k].s);
}
}
return 0;
}
1011Roundgod and Milk Tea
http://acm.hdu.edu.cn/showproblem.php?pid=6667
题意
n个班级 每个班级有若干人和若干奶茶
每个班级的人只能喝别的班级的奶茶 问最多能和多少奶茶
思路
贪心? 不明白队友的思路
队友代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct code
{
ll x,y;
} edge[1000006];
bool cmp(code a,code b)
{
if(a.x!=b.x)
return a.x>b.x;
else
return a.y<b.y;
}
ll t,n;
int main()
{
scanf("%lld",&t);
while(t--)
{
scanf("%lld",&n);
for(int i=0; i<n; i++)
scanf("%lld%lld",&edge[i].x,&edge[i].y);
sort(edge,edge+n,cmp);
ll pre=0,id=1,ans=0;
for(int i=0; i<n; i++)
{
id=max(id,(ll)i+1);
while(id<n&&edge[i].x>0)
{
if(edge[i].x>=edge[id].y)
{
edge[i].x-=edge[id].y;
ans+=edge[id].y;
edge[id++].y=0;
}
else
{
edge[id].y-=edge[i].x;
ans+=edge[i].x;
edge[i].x=0;
}
}
if(edge[i].x>=pre)
{
edge[i].x-=pre;
ans+=pre;
pre=0;
}
else
{
pre-=edge[i].x;
ans+=edge[i].x;
edge[i].x=0;
}
pre+=edge[i].y;
}
printf("%lld\n",ans);
}
return 0;
}