感觉慢慢陷入了疲态……
依旧是努力签到的一天
各种分类讨论,交上去,wa,造数据,找到bug,改一改,交上去,wa,造数据,改一改,wa,改一改,wa…循环多次后ac,然后自己也不知道自己写的是个啥了。。
后来听群里老哥们说只要离散化到5*5的格子里然后dfs就好了,明天补补看吧Orz
#include
#define ll long long
using namespace std;
int f(ll x1, ll y1, ll x2, ll y2, ll x, ll y)//1:in 2:out 3:on
{
if(x > x1 && x < x2 && y > y1 && y < y2) return 1;
if(x > x2 || x < x1 || y > y2 || y < y1) return 2;
return 3;
}
int main()
{
int T;cin>>T;
while(T--){
ll x1, y1, x2, y2, x3, y3, x4, y4;
scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
scanf("%lld%lld%lld%lld", &x3, &y3, &x4, &y4);
if(x1 == x3 && y1 == y3 && x2 == x4 && y2 == y4){
printf("2\n"); continue;
}
if(x1 > x3 || (x1 == x3 && ((y4 < y2 || y3 > y1))) ){
swap(x1,x3); swap(y1,y3); swap(x2, x4); swap(y2, y4);
}
if(x4 <= x2 && ((y4 >= y2 && y3 <= y1)) ){
if(x2 == x4){//右对齐
if(x1 == x3){
if(y1 == y3 || y2 == y4) printf("3\n");
else printf("4\n");
continue;
}
else{//x1
if(y1 == y3 && y2 == y4){
printf("3\n");continue;
}
else if(y1 == y3 || y2 == y4){
printf("4\n"); continue;
}
else printf("5\n"); continue;
}
}
else if(x1 == x3){
if(y1 == y3 && y2 == y4){
printf("3\n"); continue;
}
else if(y1 == y3 || y2 == y4){
printf("4\n"); continue;
}
else printf("5\n"); continue;
}
else if(y1 == y3 && y2 == y4)//x都不相等
{
printf("4\n"); continue;
}
else if(y1 == y3 || y2 == y4){
printf("5\n"); continue;
}
else {
printf("6\n"); continue;
}
}
int in = 0, out = 0;
int t1 = f(x1,y1,x2,y2,x3,y3);
int t2 = f(x1,y1,x2,y2,x3,y4);
int t3 = f(x1,y1,x2,y2,x4,y3);
int t4 = f(x1,y1,x2,y2,x4,y4);
if(t1 == 1||t2==1||t3==1||t4==1) in = 1;
if(t1 == 2||t2==2||t3==2||t4==2) out = 1;
if(in && out) {
printf("4\n");continue;
}
in = 0, out = 0;
t1 = f(x3, y3, x4, y4, x1, y1);
t2 = f(x3, y3, x4, y4, x1, y2);
t3 = f(x3, y3, x4, y4, x2, y1);
t4 = f(x3, y3, x4, y4, x2, y2);
if(t1 == 1||t2==1||t3==1||t4==1) in = 1;
if(t1 == 2||t2==2||t3==2||t4==2) out = 1;
if(in && out) {
printf("4\n");continue;
}
if(x1 == x3 && x2 == x4){
if(y1 < y4 && y1 > y3 && y2 > y4) printf("4\n");
else if(y2 < y4 && y2 > y3 && y1 < y3) printf("4\n");
else printf("3\n");
}
else if(y1 == y3 && y2 == y4){
if(x1 < x4 && x1 > x3 && x2 > x4) printf("4\n");
else if(x2 < x4 && x2 > x3 && x1 < x3) printf("4\n");
else printf("3\n");
}
else printf("3\n");
}
}
按题意模拟即可。如果用结构体排序的话,不要把名字也存在结构体里面,只要存一个编号就可以了,不然会T。
#include
#include
using namespace std;
const int maxn=1e5+5;
struct team
{
int id;
int num,pen;
}tea[maxn];
string name[maxn];
bool cmp(team t1,team t2)
{
if(t1.num==t2.num)return t1.pen<t2.pen;
else return t1.num>t2.num;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int T;cin>>T;
while(T--)
{
bool ok=false;
int n,d;cin>>n>>d;
for(int i=1;i<=n;i++){
cin>>name[i]>>tea[i].num>>tea[i].pen;
tea[i].id = i;
}
int ans=n*d;
if(ans%10!=5)cout<<"Quailty is very great\n";
else
{
sort(tea+1,tea+1+n,cmp);
int id = tea[ans/10+1].id;
cout<<name[id]<<'\n';
}
}
}
对于每个班级求一下有多少牛奶一定送不出去,这样得到了可以送出去的牛奶数量,和总人数求一个min就是答案。
#include
#define ll long long
using namespace std;
const int maxn = 1e6 + 50;
ll a[maxn], b[maxn];
int main()
{
int T;cin>>T;
while(T--){
int n;scanf("%d",&n);
ll sum = 0, res = 0;
ll p = 0;
for(int i = 0; i < n; ++i){
scanf("%lld%lld",&a[i],&b[i]);
sum += b[i];
p += a[i];
}
for(int i = 0; i < n; ++i){
if(p - a[i] < b[i]) res += (b[i] - (p-a[i]));
}
printf("%lld\n", min(sum - res, p));
}
}