战队:Computer room white give (CRWG)
队员:刘凯 董海铮 马鸿儒
A: Assembly Required
问题描述:
Princess Lucy broke her old reading lamp, and needs a new one. The castle orders a shipment of parts from the Slick Lamp Parts Company, which produces interchangable lamp pieces.
There are m types of lamp pieces, and the shipment contained multiple pieces of each type. Making a lamp requires exactly one piece of each type. The princess likes each piece with some value, and she likes a lamp as much as the sum of how much she likes each of the pieces.
You are part of the castle staff, which has gotten fed up with the princess lately. The staff needs to propose k distinct lamp combinations to the princess (two lamp combinations are considered distinct if they differ in at least one piece). They decide to propose the k combinations she will like the least. How much will the princess like the k combinations that the staff proposes?
输入:
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 two integers m (1 ≤ m ≤ 100), the number of lamp piece types and k (1 ≤ k ≤ 100), the number of lamps combinations to propose. The next m lines each describe the lamp parts of a type;
they begin with ni (2 ≤ ni ≤ 100), the number of pieces of this type, followed by ni integers vi,1 ,... , vi,ni(1 ≤ vi,j ≤ 10,000) which represent how much the princess likes each piece. It is guaranteed that k is no greater than the product of all ni ’s.
输出:
For each test case, output a single line containing k integers that represent how much the princess will like the proposed lamp combinations, in nondecreasing order.
input:
2
2 2
2 1 2
2 1 3
3 10
4 1 5 3 10
3 2 3 3
5 1 3 4 6 6
output:
2 3
4 5 5 6 6 7 7 7 7 7
tips:
In the first case, there are four lamp pieces, two of each type. The worst possible lamp has value 1 + 1 = 2,
while the second worst possible lamp has value 2 + 1 = 3.
题意:每组数据包含两个数m,k,m行数据每行数据选一个数,会有很多组合,输入加和前k个最小的即可。这个题可谓读题三天,做题三分钟...无解,始终维护前k个最小值即可。
#include
#include
#include
using namespace std;
int n, k;
int num[300];
int ans[300];
int a[10010];
int main()
{
int t;
cin >> t;
while (t--)
{
cin >> n >> k;
int cnt = 0;
for (int i = 1; i <= n; i++)
{
int m;
cin >> m;
for (int j = 1; j <= m; j++)
scanf("%d", &num[j]);
sort(num + 1, num + m + 1);
if (cnt == 0)
{
cnt = min(m, k);
for (int i = 1; i <= cnt; i++)
ans[i] = num[i];
}
else
{
int key = 0;
for (int k = 1; k <= cnt; k++)
for (int j = 1; j <= m; j++)
a[++key] = (ans[k] + num[j]);
sort(a + 1, a + 1 + key);
cnt = min(k, key);
for (int j = 1; j <= cnt; j++)
ans[j] = a[j];
}
}
for (int i = 1; i <= k; i++)
cout << ans[i] << " ";
cout << endl;
}
return 0;
}
补充mhr版:
#include
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
vector ans;
int n, m, maxn;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
int cnt;
cin >> cnt;
maxn = ans.size();
for (int j = 1; j <= cnt; j++)
{
int re;
cin >> re;
if (i == 1)
ans.push_back(re);
else
{
for (int k = 0; k < maxn; k++)
ans.push_back(ans[k] + re);
}
}
for (int j = 0; j < maxn; j++)
ans.erase(ans.begin());
sort(ans.rbegin(), ans.rend());
while (ans.size() > m)
ans.erase(ans.begin());
}
sort(ans.begin(), ans.end());
for (int i = 0; i < m; i++)
cout << ans[i] << " ";
cout << "\n";
}
}
B: Bulbs
问题描述
Greg has an m × n grid of Sweet Lightbulbs of Pure Coolness he would like to turn on. Initially, some of the bulbs are on and some are off. Greg can toggle some bulbs by shooting his laser at them. When he shoots his laser at a bulb, it toggles that bulb between on and off. But, it also toggles every bulb directly below it,and every bulb directly to the left of it. What is the smallest number of times that Greg needs to shoot his laser to turn all the bulbs on?
输入:
The first line of input contains a single integer T (1 ≤ T ≤ 10), the number of test cases. Each test case starts with a line containing two space-separated integers m and n (1 ≤ m, n ≤ 400). The next m lines each consist of a string of length n of 1s and 0s. A 1 indicates a bulb which is on, and a 0 represents a bulb which is off.
输出:
For each test case, output a single line containing the minimum number of times Greg has to shoot his laser to turn on all the bulbs.
input:
2
3 4
0000
1110
1110
2 2
10
00
output:
1
2
tips:
In the first test case, shooting a laser at the top right bulb turns on all the bulbs which are off, and does not
toggle any bulbs which are on.
In the second test case, shooting the top left and top right bulbs will do the job.
无解,每行都搓一边就好了....
#include
#include
C: Card Collecting
D: Double Elimination
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.
INPUT:
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
OUTPUT:
bob
peter saul
tips:In the second test case, Jill can convince Saul via Jack, and Peter was already mind-controlled.
这题赖我,因为我决策失误,上来光想写并查集wa的太多,甚至整个团队都丢了士气,赛后用连边加搜索一发就A了,唉,拖我出去祭天吧....
分析:离散化各人名,然后对于m条A控制B的信息,对A和B连一条单向边,然后对A进行搜索,能搜到的点全打标记,最后在B组中找被打标记的人名就是答案。刚开始我也是这么做,只不过是反向搜索,从B到A结果无限爆内存,正向搜就过了,这或许大概就是算法竞赛的神奇之处吧...
#include
#include
#include
#include
#include
#include
#include
后来看到其他学校同学的写法,还有网上的写法,大同小异....
F: Flight Plan
G: Ground Defense
题目描述
You are a denizen of Linetopia, whose n major cities happen to be equally spaced along an east-west line. In fact, they are often numbered in order from 1 to n, where 1 is the westmost city and n is the eastmost city.
Linetopia was a lovely place to live until forces from neighboring Trapez invaded. As part of Linetopia’s Shielding Lives and Protecting Citizens initiative, you have been called upon to process information about Trapezoid troop movements so we can determine which cities have been hardest hit and know where to send reinforcements.
Linetopia intelligence has discovered that the Trapezoid forces are attacking in the following pattern. They are sending massive aircraft to drop troops on Linetopia cities. Each aircraft starts at some city i, dropping s soldiers. The aircraft then proceeds to fly either east or west. Each time it flies over another city, it drops a more soldiers than it dropped on the previous city it passed. After performing d drops, the aircraft returns to Trapez to resupply.
You will be receiving intel updates that inform you of the specs of each Trapezoid aircraft passing over Linetopia. You want to answer queries that ask how many Trapezoid troops have been dropped on a particular city. Are you up to the task?
输入
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 two integers: m (1 ≤ m ≤ 10,000), the number of updates and queries and n (1 ≤ n ≤ 500,000), the number of cities in Linetopia.
The next m lines of input are either updates or queries. Update lines begin with a capital U, then contain either a capital E (east) or W (west) to indicate direction, and then contain four integers i (1 ≤ i ≤ n), s (1 ≤ s ≤ 10,000), a (0 ≤ a ≤ 10,000), and d (1 ≤ d ≤ n). These integers signify the starting city, the starting number of soldiers, the increase in soldiers per city, and the number of drops, respectively. You can assume d never results in an aircraft flying to the west of city 1 or to the east of city n.
Query lines begin with a capital Q, and then contain a single integer i (1 ≤ i ≤ n) indicating the city being queried.
输出
For each query in the input, output a single line containing the number of Trapezoid troops dropped in that city.
INPUT:
1
8 3
U E 1 5 2 3
Q 1
Q 2
Q 3
U W 3 10 10 2
Q 1
Q 2
Q 3
OUTPUT:
1
8 3
U E 1 5 2 3
Q 1
Q 2
Q 3
U W 3 10 10 2
Q 1
Q 2
Q 3
这个是暴力??比赛时我们队光玩线段树,白给....赛后mhr一通暴力无解AC,太狗了,菜是原罪...
#include
using namespace std;
struct node
{
long long l,a,d,r;
}E[10005],W[10005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n,m,p=0,q=0;
cin>>n>>m;
while(n--)
{
char x;
cin>>x;
if(x=='U')
{
char y;
cin>>y;
long long l,a,d,r;
cin>>l>>a>>d>>r;
if(y=='E')
E[p++]=(node){l,a,d,r};
else
W[q++]=(node){l,a,d,r};
}
else
{
long long now;
cin>>now;
long long ans=0;
for(int i=0;i=E[i].l&&now<=E[i].l+E[i].r-1)
ans+=1LL*E[i].a+(now-E[i].l)*E[i].d;
}
for(int i=0;i=W[i].l-W[i].r+1&&now<=W[i].l)
ans+=1LL*W[i].a+(W[i].l-now)*W[i].d;
}
cout<
H: Hunter’s Apprentice
#include
using namespace std;
struct v
{
double x,y;
}pt[66];
double cross(v a,v b)
{
return a.x*b.y-a.y*b.x;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n;
double sum=0;
cin>>n;
for(int i=1;i<=n;i++)
cin>>pt[i].x>>pt[i].y;
for(int i=2;i<=n-1;i++)
sum+=0.5*cross((v){pt[i].x-pt[1].x,pt[i].y-pt[1].y},(v){pt[i+1].x-pt[1].x,pt[i+1].y-pt[1].y});
if(sum>0)
cout<<"fight\n";
else
cout<<"run\n";
}
}
I: Ingenious Lottery Tickets
题目描述
Your friend Superstitious Stanley is always getting himself into trouble. This time, in his Super Lotto Pick and Choose plan, he wants to get rich quick by choosing the right numbers to win the lottery. In this lottery, entries consist of six distinct integers from 1 to 49, which are written in increasing order. Stanley has compiled a list of winning entries from the last n days, and is going to use it to pick his winning numbers.
In particular, Stanley will choose the six numbers that appeared the most often. When Stanley is breaking ties, he prefers smaller numbers, except that he prefers seven to every other number. What is Stanley’s entry?
输入
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 (1 ≤ n ≤ 1,000), the number of winning entries that Stanley compiled. The next n lines each contain a lottery entry as described above.
输出
For each test case, output a single line containing Stanley’s entry.
水题,haizheng Tung 一发过
#include
using namespace std;
struct vec{
int name,d;
}p[50];
int a[7];
bool cmp(vec a,vec b)
{
if(a.d==b.d)
return a.nameb.d;
}
int main()
{
int t;
cin>>t;
while(t--)
{
memset(p,0,sizeof(p));
memset(a,0,sizeof(a));
int n;
cin>>n;
for(int i=1;i<=n;i++)
for(int j=0;j<6;j++){
int x;
cin>>x;
p[x].d++;
p[x].name=x;
}
int bk=1,f=p[7].d;
sort(p+1,p+50,cmp);
for(int i=1;i<=6;i++){
if(p[i].name==7)
bk=0;
a[i]=p[i].name;
}
if(f>=p[6].d&&bk)
a[6]=7;
sort(a+1,a+7);
for(int i=1;i<=6;i++)
cout<
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.
INPUT:
2
1
1 1
3
0 0
1 4
3 2
OUTPUT:
0
4
TIPS:
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.
#include
using namespace std;
struct node
{
int x,y;
}num[666];
bool cmp1(node a,node b)
{
return a.x>t;
while(t--)
{
int n,ans=INT_MAX;
cin>>n;
for(int i=0;i>num[i].x>>num[i].y;
sort(num,num+n,cmp1);
int sum=n/2+1;
for(int i=0;i now;
for(int k=i;k<=j;k++)
now.push_back(num[k]);
sort(now.begin(),now.end(),cmp2);
for(int k=0;k<=now.size()-sum;k++)
ans=min(ans,cha*abs(now[k].y-now[k+sum-1].y));
}
cout<