中石油第五场补

9 篇文章 0 订阅
3 篇文章 0 订阅

 E: Election of Evil

题目描述

Dylan is a corrupt politician trying to steal an election. He has already used a mind-control technique to enslave some set U of government representatives. However, the representatives who will be choosing the winner of the election is a different set V . Dylan is hoping that he does not need to use his mind-control device again, so he is wondering which representatives from V can be convinced to vote for him by representatives from U.
Luckily, representatives can be persuasive people. You have a list of pairs (A, B) of represenatives, which indicate that A can convice B to vote for Dylan. These can work in chains; for instance, if Dylan has mind-controlled A, A can convince B, and B can convince C, then A can effectively convince C as well.

 

输入

The first line contains a single integer T (1 ≤ T ≤ 10), the number of test cases. The first line of each test case contains three space-separated integers, u, v, and m (1 ≤ u, v, m ≤ 10,000). The second line contains a space-separated list of the u names of representatives in U. The third line contains a space-separated list of the v names of representatives from V . Each of the next m lines contains a pair of the form A B, where A and B are names of two representatives such that A can convince B to vote for Dylan. Names are strings of length between 1 and 10 that only consists of lowercase letters (a to z).

 

输出

For each test case, output a space-separated list of the names of representatives from T who can be convinced to vote for Dylan via a chain from S, in alphabetical order.

 

样例输入

复制样例数据

2
1 1 1
alice
bob
alice bob
5 5 5
adam bob joe jill peter
rob peter nicole eve saul
harry ron
eve adam
joe chris
jill jack
jack saul

样例输出

bob
peter saul

提示

In the second test case, Jill can convince Saul via Jack, and Peter was already mind-controlled.

题意:第一行一行人名是已经被控制的,第二行再给出一串人名,然后一系列关系:哪些人可以说服哪一些人,

问第二行中的人有哪一些可以被第一行的人说服?按字典序输出

首先想到并查集,,但是看到那么多人写不出。。。还是写了个搜索。。。将第二行中的人输入时打个标记,这样在搜索的时候可以判断哪些是要求的人名,然后一个string数组和一个map分别记录人名和编号,将两两关系计入vector中,最后按第一行中的人名搜索

#include<bits/stdc++.h>
using namespace std;
const int N=3e4+10;
map<string,int>mp1,mp2;
string b[N],s1,s2;
int vis[N],p[N],vis2[N],c[N];
vector<int>que[N];
void dfs(int x)
{
    vis2[x]=1;
    if(vis[x]==1)
        mp2[b[x]]=1;
    for(int i=0;i<que[x].size();i++){
        if(!vis2[que[x][i]])
            dfs(que[x][i]);
    }
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
            int n,m,u;
    for(int i=0;i<30001;i++)
        que[i].clear();
        mp1.clear();
        mp2.clear();
        memset(vis,0,sizeof(vis));
        memset(vis2,0,sizeof(vis2));
        int num=0;
        cin>>n>>m>>u;
        for(int i=1;i<=n;i++){
                cin>>s1;
            if(!mp1[s1]){
                b[++num]=s1;
                mp1[s1]=num;
            }
            c[i]=mp1[s1];   //记录第一行人名的编号,方便下面搜索
        }
        for(int i=1;i<=m;i++){
            cin>>s1;
            if(!mp1[s1]){
                b[++num]=s1;
                mp1[s1]=num;
            }
            vis[mp1[s1]]=1;  //标记第二行人名
        }
        for(int i=1;i<=u;i++){
            cin>>s1>>s2;
            if(!mp1[s1]){
                b[++num]=s1;
                mp1[s1]=num;
            }
            if(!mp1[s2]){
                b[++num]=s2;
                mp1[s2]=num;
            }
            que[mp1[s1]].push_back(mp1[s2]);
        }
        for(int i=1;i<=n;i++){
            if(!vis2[c[i]])
                dfs(c[i]);
        }
        int first=1;
        map<string,int>::iterator it;
      for(it=mp2.begin();it!=mp2.end();it++){
      if(first){
        first=0;
        cout<<it->first;
      }
      else cout<<" "<<it->first;
      }
        printf("\n");
    }
}

 H: Hunter’s Apprentice

题目描述

When you were five years old, you watched in horror as a spiked devil murdered your parents. You would have died too, except you were saved by Rose, a passing demon hunter. She ended up adopting you and training you as her apprentice.
Rose’s current quarry is a clock devil which has been wreaking havoc on the otherwise quiet and unassuming town of Innsmouth. It comes out each night to damage goods, deface signs, and kill anyone foolish enough to wander around too late. The clock devil has offed the last demon hunter after it; due to its time-warping powers, it is incredibly agile and fares well in straight-up fights.
The two of you have spent weeks searching through dusty tomes for a way to defeat this evil. Eventually, you stumbled upon a relevant passage. It detailed how a priest managed to ensnare a clock devil by constructing a trap from silver, lavender, pewter, and clockwork. The finished trap contained several pieces, which must be placed one-by-one in the shape of a particular polygon, in counter-clockwise order. The book stated that the counter-clockwise order was important to counter the clock devil’s ability to speed its own time up, and that a clockwise order would only serve to enhance its speed.
It was your responsibility to build and deploy the trap, while Rose prepared for the ensuing fight. You carefully reconstruct each piece as well as you can from the book. Unfortunately, things did not go as planned that night. Before you can finish preparing the trap, the clock devil finds the two of you. Rose tries to fight the devil, but is losing quickly. However, she is buying you the time to finish the trap. You quickly walk around them in the shape of the polygon, placing each piece in the correct position. You hurriedly activate the trap as Rose is knocked out. Just then, you remember the book’s warning. What should you do next?

 

输入

The first line of input contains a single integer T (1 ≤ T ≤ 100), the number of test cases. The first line of each test case contains a single integer n (3 ≤ n ≤ 20), the number of pieces in the trap. Each of the next n lines contains two integers xi and yi (|xi |, |yi | ≤ 100), denoting the x and y coordinates of where the ith piece was placed. It is guaranteed that the polygon is simple; edges only intersect at vertices, exactly two edges meet at each vertex, and all vertices are distinct.

 

输出

For each test case, output a single line containing either fight if the trap was made correctly or run if the trap was made incorrectly.

 

样例输入

复制样例数据

2
3
0 0
1 0
0 1
3
0 0
0 1
1 0

样例输出

fight
run

提示

In the first case, you went around the polygon in the correct direction, so it is safe to fight the clock devil
and try to save Rose.
In the second case, you messed up, and it is time to start running. Sorry Rose!

题目一大串,有用的其实没有多少。。。就是给n个点,判断按给出的顺序输入的n个点是顺时针输入还是逆时针输入

这个题不懂公式的话,,那真是硬做啊......一个个特殊条件特判。。然后仍然过不了。。。

有了公式就几行的事,凸包的话找前三个点判断叉积,凹包麻烦的方法也没记,记了一个最简单的计算面积,大于0顺时针,小于0逆时针,计算面积的方法凸包凹包都适用。

叉乘
double cross(Point a,Point b,Point c) {
    return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
#include<bits/stdc++.h>
#define exp 1e-8
#define mian main
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define pb push_back
#define PI  acos(-1.0)
#define inf 0x3f3f3f3f
#define w(x) while(x--)
#define int_max 2147483647
#define lowbit(x) (x)&(-x)
#define gcd(a,b) __gcd(a,b)
#define pq(x)  priority_queue<x>
#define ull unsigned long long
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pl(a,n) next_permutation(a,a+n)
#define ios ios::sync_with_stdio(false)
#define met(a,x) memset((a),(x),sizeof((a)))
using namespace std;
struct node
{
    double x;
    double y;
}p[30];
int n;
bool getarea()
{
    double ans=0.0;
    for(int i=1;i<n;i++)
        ans+=p[i].x*p[i+1].y-p[i+1].x*p[i].y;
    ans+=p[n].x*p[1].y-p[n].y*p[1].x;
    ans*=0.5;
    if(ans>0)
        return true;
    else return false;
}
int main()
{
    int t;
    sc(t);
    while(t--){
        sc(n);
        for(int i=1;i<=n;i++)
            scanf("%lf%lf",&p[i].x,&p[i].y);
        if(getarea())
            printf("fight\n");
        else printf("run\n");
    }
}

 J: Jurisdiction Disenchantment

题目描述

The Super League of Paragons and Champions (SLPC) has been monitoring a plot by a corrupt politician to steal an election. In the past week, the politican has used a mind-control technique to enslave the n representatives responsible for choosing the election’s winner. Luckily, the SLPC has managed to recruit you and hence has access to your power to break mind-control. You are able to break mind-control in an axis-aligned rectangle. Unfortunately, your power comes at a steep cost; you get a headache the next day proportional to the size of the rectangle. You do not even want to risk or think about what would happen if you tried to use your power multiple times in one day.
You have done your research and you know the position that each representative will be standing when the votes are about to be cast. You need to free enough representatives to prevent the politician from having a majority (strictly more than one-half) vote. What is the area of the smallest axis-aligned rectangle that you can affect to do this?

 

输入

The first line of input contains a single integer T (1 ≤ T ≤ 10), the number of test cases. The first line of each test case contains a single integer n (1 ≤ n ≤ 299, n is odd), the number of representatives. Each of the next n lines of input contains two integers, denoting the x and y coordinates of a representative. It is guaranteed that all coordinates are between −10,000 and +10,000.

 

输出

For each test case, output a single line containing the area of the smallest axis-aligned rectangle containing more than n/2 of the representatives.

 

样例输入

复制样例数据

2
1
1 1
3
0 0
1 4
3 2

样例输出

0
4

提示

In the first case, a rectangle containing a single point has an area of 0.
In the second test case, the rectangle needs to include at least two points. There are two smallest possible
rectangles; one includes (0, 0) and (1, 4) and the other includes (1, 4) and (3, 2). In either case, the area is
4.

给出n个点,问在至少包含n/2个点的情况下,计算出最小的矩形面积。

既然只有最多299个点,暴力找就好了。。。

先按x坐标从小到大排序,依次找两个点之间的点,找出来的点在按y坐标从小到大排序,计算最小面积

#include<bits/stdc++.h>
#define exp 1e-8
#define mian main
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define pb push_back
#define PI  acos(-1.0)
#define inf 0x3f3f3f3f
#define w(x) while(x--)
#define int_max 2147483647
#define lowbit(x) (x)&(-x)
#define gcd(a,b) __gcd(a,b)
#define pq(x)  priority_queue<x>
#define ull unsigned long long
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pl(a,n) next_permutation(a,a+n)
#define ios ios::sync_with_stdio(false)
#define met(a,x) memset((a),(x),sizeof((a)))
using namespace std;
const int N=300;
int n;
struct node
{
    int x,y;
}a[310],p[310];
bool cmp1(node a,node b)
{
    if(a.x==b.x)
        return a.y<b.y;
    else return a.x<b.x;
}
bool cmp2(node a,node b)
{
    if(a.y==b.y)
        return a.x<b.x;
    else return a.y<b.y;
}
int main()
{
    int t;
    sc(t);
    while(t--){
        sc(n);
        int ans=inf;
        int num=n/2+1;
        for(int i=1;i<=n;i++)
            scanf("%d%d",&a[i].x,&a[i].y);
            if(n==1){
            printf("0\n");
            continue;
        }
        sort(a+1,a+1+n,cmp1);
        for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++){
                int x1=a[i].x;
                int x2=a[j].x;
                int tot=0;
            for(int k=i;k<=j;k++)
              p[++tot]=a[k];
        sort(p+1,p+1+tot,cmp2);
        for(int k=1;k<=tot-num+1;k++){
            int y1=p[k].y;
            int y2=p[k+num-1].y;
            ans=min(ans,(y1-y2)*(x1-x2));
        }
        }
        printf("%d\n",ans);
    }
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值