qdu_组队训练(ABCFIJK)
A - Second-price Auction
Do you know second-price auction? It's very simple but famous. In a second-price auction, each potential buyer privately submits, perhaps in a sealed envelope or over a secure connection, his (or her) bid for the object to the auctioneer. After receiving all the bids, the auctioneer then awards the object to the bidder with the highest bid, and charges him (or her) the amount of the second-highest bid.
Suppose you're the auctioneer and you have received all the bids, you should decide the winner and the amount of money he (or she) should pay.
Input
There are multiple test cases. The first line of input contains an integer T(T <= 100), indicating the number of test cases. Then T test cases follow.
Each test case contains two lines: The first line of each test case contains only one integer N, indicating the number of bidders. (2 <= N <= 100) The second line of each test case contains N integers separated by a space. The i-th integer Piindicates the i-th bidder's bid. (0 < Pi <= 60000) You may assume that the highest bid is unique.
Output
For each test case, output a line containing two integers x and y separated by a space. It indicates that the x-th bidder is the winner and the amount of money he (or she) should pay is y.
Sample Input
2
3
3 2 1
2
4 9
Sample Output
1 2
2 4
水题,上代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
const int maxn=1e5+5;
typedef long long ll;
using namespace std;
int a[maxn];
int b[maxn];
int main()
{
int T;
while(cin>>T)
{
while(T--)
{
int n;
cin>>n;
for(int t=0;t<n;t++)
{
scanf("%d",&a[t]);
b[t]=a[t];
}
sort(a,a+n);
int k;
for(int t=0;t<n;t++)
{
if(b[t]==a[n-1])
{
k=t+1;
}
}
cout<<k<<" "<<a[n-2]<<endl;
}
}
return 0;
}
Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodious house, thinking of how to earn more money. One day, he found that the length of his shadow was changing from time to time while walking between the light bulb and the wall of his house. A sudden thought ran through his mind and he wanted to know the maximum length of his shadow.
Input
The first line of the input contains an integer T (T <= 100), indicating the number of cases.
Each test case contains three real numbers H, h and D in one line. H is the height of the light bulb while h is the height of mildleopard. D is distance between the light bulb and the wall. All numbers are in range from 10-2 to 103, both inclusive, and H - h >= 10-2.
Output
For each test case, output the maximum length of mildleopard's shadow in one line, accurate up to three decimal places..
Sample Input
3
2 1 0.5
2 0.5 3
4 3 4
Sample Output
1.000
0.750
4.000
三分 附队友代码
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
double H,h,D;
double fun(double x)
{
return 1.0*h/(1.0*x*(H-h)/(D*h-H*x)+1)+1.0*x;
}
double sanfen(double l,double r)
{
if(r-l<0.00001)
return fun(l);
double mid=(l+l+r)/3;
double midd=(l+r+r)/3;
double a=fun(mid);
double b=fun(midd);
if(a>b)
return sanfen(l,midd);
else
return sanfen(mid,r);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf",&H,&h,&D);
double tt=1.0*D*h/H;
printf("%.3f\n",sanfen(0,tt));
}
}
You have n computers numbered from 1 to n and you want to connect them to make a small local area network (LAN). All connections are two-way (that is connecting computers i and j is the same as connecting computers j and i). The cost of connecting computer i and computer j is cij. You cannot connect some pairs of computers due to some particular reasons. You want to connect them so that every computer connects to any other one directly or indirectly and you also want to pay as little as possible.
Given n and each cij , find the cheapest way to connect computers.
Input
There are multiple test cases. The first line of input contains an integer T (T <= 100), indicating the number of test cases. Then T test cases follow.
The first line of each test case contains an integer n (1 < n <= 100). Then n lines follow, each of which contains n integers separated by a space. The j-th integer of the i-th line in these n lines is cij, indicating the cost of connecting computers iand j (cij = 0 means that you cannot connect them). 0 <= cij <= 60000, cij = cji, cii= 0, 1 <= i, j <= n.
Output
For each test case, if you can connect the computers together, output the method in in the following fomat:
i1 j1 i1 j1 ......
where ik ik (k >= 1) are the identification numbers of the two computers to be connected. All the integers must be separated by a space and there must be no extra space at the end of the line. If there are multiple solutions, output the lexicographically smallest one (see hints for the definition of "lexicography small") If you cannot connect them, just output "-1" in the line.
Sample Input
2
3
0 2 3
2 0 5
3 5 0
2
0 0
0 0
Sample Output
1 2 1 3
-1
Hint
s:
A solution A is a line of p integers: a1, a2, ...ap.
Another solution B different from A is a line of q integers: b1, b2, ...bq.
A is lexicographically smaller than B if and only if:
(1) there exists a positive integer r (r <= p, r <= q) such that ai = bi for all 0 < i < r and ar < br
OR
(2) p < q and ai = bi for all 0 < i <= p
最小生成树
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
const int maxn=1e2+10;
typedef long long ll;
using namespace std;
int pre[maxn];
struct node
{
int x,y;
int sum;
}p[1000005];
struct node1
{
int x,y;
}mp[1000005];
int find(int x)
{
if(pre[x]==x)
{
return x;
}
else
{
return pre[x]=find(pre[x]);
}
}
bool merge(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx!=fy)
{
pre[fx]=fy;
return true;
}
else
{
return false;
}
}
bool cmp(node x1,node y1)
{
if(x1.sum!=y1.sum)
return x1.sum<y1.sum;
else
{
if(x1.x!=y1.x)
{
return x1.x<y1.x;
}
else
{
return x1.y<y1.y;
}
}
}
bool cmp1( node1 a, node1 b){
if(a.x == b.x){
return a.y < b.y;
}
else
return a.x < b.x;
}
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
for(int t=1;t<=n;t++)
{
pre[t]=t;
}
int cnt=0;
for(int t=1;t<=n;t++)
{
for(int j=1;j<=n;j++)
{
int x;
scanf("%d",&x);
if(x!=0&&t<j)
{
p[cnt].x=t;
p[cnt].y=j;
p[cnt++].sum=x;
}
}
}
sort(p,p+cnt,cmp);
int cc=0;
for(int t=0;t<cnt;t++)
{
if(cc==n-1)
{
break;
}
if(merge(p[t].x,p[t].y))
{
mp[cc].x=p[t].x;
mp[cc].y=p[t].y;
cc++;
}
}
if(cc!=n-1)
{
cout<<"-1"<<endl;
continue;
}
sort(mp,mp+cc,cmp1);
for(int t=0;t<cc;t++)
{
if(t==0)
cout<<mp[t].x<<" "<<mp[t].y;
else
{
cout<<" "<<mp[t].x<<" "<<mp[t].y;
}
}
cout<<endl;
}
return 0;
}
I guess most of us are so called 80ers, which means that we were born in the 1980's. This group of people shared a lot of common memories. For example, the Saint Seiya, the YoYo ball, the Super Mario, and so on. Do you still remember these?
Input
There will be ONLY ONE test case.
The test case begins with a positive integer N, (N < 100).
Then there will be N lines each containing a single word describing a keyword of the typical 80ers' memories. Each word consists of letters, [a-zA-Z], numbers, [0-9], and the underline, '_'. The length of each word would be no more than 20.
Then one line follows with a positive integer K, (K < 100).
The last part of the test case will be K lines. The i-th line contains the keywords given by the i-th person and starts with a positive integer Ni. Then there will be Ni words separated by white spaces. Each of these words has no more than 20 characters.
All the words are case sensitive.
Output
For each of these K people, you are asked to count the number of typical 80ers' keywords on his/her list and output it in a single line.
Sample Input
4
Saint_Seiya
YoYo_ball
Super_Mario
HuLuWa
3
2 Saint_Seiya TiaoFangZi
1 KTV
3 HuLuWa YOYO_BALL YoYo_ball
Sample Output
1
0
2
map
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
const int maxn=1e5+5;
typedef long long ll;
using namespace std;
int a[maxn];
int b[maxn];
char str[1005][1005];
map<string,int>mp;
int main()
{
int n;
cin>>n;
getchar();
for(int t=1;t<=n;t++)
{
scanf("%s",&str[t]);
mp[str[t]]=t;
}
int k;
cin>>k;
for(int t=0;t<k;t++)
{
int m;
cin>>m;
int s=0;
getchar();
char str2[105];
for(int j=0;j<m;j++)
{
cin>>str2;
if(mp[str2]!=0)
{
s++;
}
}
cout<<s<<endl;
}
return 0;
}
I - A Stack or A Queue?
Do you know stack and queue? They're both important data structures. A stack is a "first in last out" (FILO) data structure and a queue is a "first in first out" (FIFO) one.
Here comes the problem: given the order of some integers (it is assumed that the stack and queue are both for integers) going into the structure and coming out of it, please guess what kind of data structure it could be - stack or queue?
Notice that here we assume that none of the integers are popped out before all the integers are pushed into the structure.
Input
There are multiple test cases. The first line of input contains an integer T (T <= 100), indicating the number of test cases. Then T test cases follow.
Each test case contains 3 lines: The first line of each test case contains only one integer N indicating the number of integers (1 <= N <= 100). The second line of each test case contains N integers separated by a space, which are given in the order of going into the structure (that is, the first one is the earliest going in). The third line of each test case also contains N integers separated by a space, whick are given in the order of coming out of the structure (the first one is the earliest coming out).
Output
For each test case, output your guess in a single line. If the structure can only be a stack, output "stack"; or if the structure can only be a queue, output "queue"; otherwise if the structure can be either a stack or a queue, output "both", or else otherwise output "neither".
Sample Input
4
3
1 2 3
3 2 1
3
1 2 3
1 2 3
3
1 2 1
1 2 1
3
1 2 3
2 3 1
Sample Output
stack
queue
both
neither
模拟
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
const int maxn=1e5+5;
typedef long long ll;
using namespace std;
int a[maxn];
int b[maxn];
int main()
{
int T;
queue<int>q;
stack<int>s;
while(cin>>T)
{
while(T--)
{
int n;
cin>>n;
for(int t=0;t<n;t++)
{
scanf("%d",&a[t]);
q.push(a[t]);
s.push(a[t]);
}
for(int t=0;t<n;t++)
{
scanf("%d",&b[t]);
}
int flag1=0,flag2=0;
for(int t=0;t<n;t++)
{
if(b[t]!=q.front())
{
flag2=1;
}
if(b[t]!=s.top())
{
flag1=1;
}
q.pop();
s.pop();
}
if(flag1==1&&flag2==1)
{
cout<<"neither"<<endl;
}
else if(flag1==1&&flag2==0)
{
cout<<"queue"<<endl;
}
else if(flag1==0&&flag2==1)
{
cout<<"stack"<<endl;
}
else
{
cout<<"both"<<endl;
}
}
}
return 0;
}
JAVAMAN is visiting Dream City and he sees a yard of gold coin trees. There are ntrees in the yard. Let's call them tree 1, tree 2 ...and tree n. At the first day, each tree i has ai coins on it (i=1, 2, 3...n). Surprisingly, each tree i can grow bi new coins each day if it is not cut down. From the first day, JAVAMAN can choose to cut down one tree each day to get all the coins on it. Since he can stay in the Dream City for at most m days, he can cut down at most m trees in all and if he decides not to cut one day, he cannot cut any trees later. (In other words, he can only cut down trees for consecutive m or less days from the first day!)
Given n, m, ai and bi (i=1, 2, 3...n), calculate the maximum number of gold coins JAVAMAN can get.
Input
There are multiple test cases. The first line of input contains an integer T (T <= 200) indicates the number of test cases. Then T test cases follow.
Each test case contains 3 lines: The first line of each test case contains 2 positive integers n and m (0 < m <= n <= 250) separated by a space. The second line of each test case contains n positive integers separated by a space, indicating ai. (0 < ai <= 100, i=1, 2, 3...n) The third line of each test case also contains npositive integers separated by a space, indicating bi. (0 < bi <= 100, i=1, 2, 3...n)
Output
For each test case, output the result in a single line.
Sample Input
2
2 1
10 10
1 1
2 2
8 10
2 3
Sample Output
10
21
Hint
s:
Test case 1: JAVAMAN just cut tree 1 to get 10 gold coins at the first day.
Test case 2: JAVAMAN cut tree 1 at the first day and tree 2 at the second day to get 8 + 10 + 3 = 21 gold coins in all.
dp,要让效益好的往后排,如果相同就数值大的在前面
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
const int maxn=300;
typedef long long ll;
using namespace std;
int dp[maxn][maxn];
struct node
{
int val,speed;
}p[1005];
bool cmp(node x,node y)
{
if(x.speed!=y.speed)
{
return x.speed<y.speed;
}
else
{
return x.val>y.val;
}
}
int main()
{
int T;
while(cin>>T)
{
while(T--)
{
int n,m;
memset(dp,0,sizeof(dp));
cin>>n>>m;
for(int t=1;t<=n;t++)
{
scanf("%d",&p[t].val);
}
for(int j=1;j<=n;j++)
{
scanf("%d",&p[j].speed);
}
sort(p+1,p+n+1,cmp);
for(int t=1;t<=n;t++)
{
for(int j=1;j<=m;j++)
{
dp[t][j]=max(dp[t-1][j],dp[t-1][j-1]+p[t].speed*(j-1)+p[t].val);
}
}
cout<<dp[n][m]<<endl;
}
}
return 0;
}
This is a super simple problem. The description is simple, the solution is simple. If you believe so, just read it on. Or if you don't, just pretend that you can't see this one.
We say an element is inside a matrix if it has four neighboring elements in the matrix (Those at the corner have two and on the edge have three). An element inside a matrix is called "nice" when its value equals the sum of its four neighbors. A matrix is called "k-nice" if and only if k of the elements inside the matrix are "nice".
Now given the size of the matrix and the value of k, you are to output any one of the "k-nice" matrix of the given size. It is guaranteed that there is always a solution to every test case.
Input
The first line of the input contains an integer T (1 <= T <= 8500) followed by Ttest cases. Each case contains three integers n, m, k (2 <= n, m <= 15, 0 <= k <= (n- 2) * (m - 2)) indicating the matrix size n * m and it the "nice"-degree k.
Output
For each test case, output a matrix with n lines each containing m elements separated by a space (no extra space at the end of the line). The absolute value of the elements in the matrix should not be greater than 10000.
Sample Input
2
4 5 3
5 5 3
Sample Output
2 1 3 1 1
4 8 2 6 1
1 1 9 2 9
2 2 4 4 3
0 1 2 3 0
0 4 5 6 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
思维,初始化全是0,其余都填数,每天一个减少一个符合的
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
const int maxn=30;
typedef long long ll;
int Map[maxn][maxn];
using namespace std;
int main()
{
int T;
while(cin>>T)
{
while(T--)
{
memset(Map,0,sizeof(Map));
int n,m,k;
cin>>n>>m>>k;
int s=(n-2)*(m-2);
int cnt=2;
int flag=0;
for(int t=0;t<n&&flag==0;t++)
{
for(int j=0;j<m;j++)
{
if(t==n-1||j==0||j==m-1)
{
continue;
}
if(s==k)
{
flag=1;
break;
}
Map[t][j]=cnt++;
s--;
}
}
for(int t=0;t<n;t++)
{
for(int j=0;j<m;j++)
{
if(j==0)
{
printf("%d",Map[t][j]);
}
else
{
printf(" %d",Map[t][j]);
}
}
printf("\n");
}
}
}
return 0;
}
qdu_组队训练(ABCFIJK)的更多相关文章
- QDU_组队训练(ABEFGHKL)
A - Accurately Say "CocaCola"! In a party held by CocaCola company, several students stand ...
- QDU_组队训练(AJFC)
A - Pretty Matrix DreamGrid's birthday is coming. As his best friend, BaoBao is going to prepare a g ...
- 组队训练3回放 ——hnqw1214
组队训练3回放 练习赛过程回放: 开场先看最后一题, 发现是专题训练时做过的网络流原题, cst照着之前的打一遍,第一遍WA, 发现数组开小了,改大后AC. 这时候qw看B题, 一开始想不到方法, c ...
- 组队训练1 回放(转载至cxhscst2's blog)
第一场组队训练……意料之中的爆炸. 开场先看题,H是斐波那契水题,qw把H切了. 同时czy看I题(排列),cst继续读其他题. czy尝试交I,PE. cst发现K是水题. cst上来敲K,WA ...
- 组队训练2 回放(转载至cxhscst2's blog)
2017/3/4 12:00-17:00 Solve 9 / 13 Penalty 717 练习赛过程回放: 开场5分中J题签到(cst) 12分钟时qw签到A 这时qw继续开写M,WA,检查代码. ...
- 【组队训练】2016 ACM/ICPC Asia Regional Dalian Online
因为不是一队……毫无晋级的压力……反正有压力也进不去呵呵呵…… 开场zr看1006我看1010.. 1010我一直在wa... zr的1006倒是比较轻松的过了...然后我让他帮我看10.... 跟他 ...
- 【组队训练】2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest
好多oj都崩掉了,于是打了cf.. 开始开的最后一题...尼玛题好长终于看完了...神题不会.... I过了好多人..看了下,一眼题...随便敲了下,1A ]; int main(){ int n, ...
- 问题 J: Palindromic Password ( 2018组队训练赛第十五场) (简单模拟)
问题 J: Palindromic Password 时间限制: 3 Sec 内存限制: 128 MB提交: 217 解决: 62[提交][状态][讨论版][命题人:admin] 题目描述 The ...
- 问题 C: Frosh Week(2018组队训练赛第十五场)(签到)
问题 C: Frosh Week 时间限制: 4 Sec 内存限制: 128 MB提交: 145 解决: 63[提交][状态][讨论版][命题人:admin] 题目描述 Professor Zac ...
随机推荐
- SqlDataAdapter 批量更新数据库表
在数据库中批量插入数据许多人都已经了解了,就是使用.net 中的SqlBulkCopy对象(MSDN详解).我们在做评教系统的时候使用过这个对象,它能将数据表批量导入到数据库中,效率比单条插入数据效率 ...
- Part10-C语言环境初始化-Bss段初始化lesson2
1.BSS段的作用 初始化的全局变量存放在数据段: 局部变量存放在栈中: malloc的存放在堆: 未初始化的全局变量存放在BSS段: 找到bss段的起始与结束地址,往里面添加0,便初始化好了. 打开 ...
- delphi将图片转换成Base64编码函数
{************************************************************************** 名称: BaseImage 参数: fn: TF ...
- 做ETL的时候用到的数据同步更新代码
这里是用的从一个库同步到另一个库,代码如下 private void IncrementalSyncUpdate(string fromConn, string toConn, Dictionary& ...
- 「JSOI2009」球队收益 / 球队预算
题目链接 戳我 \(Solution\) 我们发现这道题目并不好做,因为要考虑两个因素对答案的影响.于是我们假设接下来的\(m\)场比赛双方都输了.这要我们就只要考虑赢一场对答案的影响了,那每赢一场输 ...
- leecode刷题(4)-- 存在重复数组
leecode刷题(4)-- 存在重复数组 存在重复数组 题目描述: 给定一个整数数组,判断是否存在重复元素. 如果任何值在数组中出现至少两次,函数返回 true.如果数组中每个元素都不相同,则返回 ...
- 【ARC075F】Mirrored 搜索/数位dp
Description 给定正整数DD,求有多少个正整数NN,满足rev(N)=N+Drev(N)=N+D,其中rev(N)rev(N)表示将NN的十进制表示翻转来读得到的数 Input 一个 ...
- 题解 UVA10212 【The Last Non-zero Digit.】
题目链接 这题在学长讲完之后和看完题解之后才明白函数怎么构造. 这题构造一个$f(n)$ $f(n)$ $=$ $n$除以 $2^{a}$ $*$ $5^{b}$ ,$a$ , $b$ 分别是 $n$ ...
- LAMP课程(3)
LAMP课程(3) 一.bash的使用 1.1.输出重定向 >:覆盖输出(写入内容) 具体实例1:将内容写入到文件中 >>:追加输出 具体实例2: 1.2 && ...
- 自动备份数据库crond
#!/bin/bash # export and backup the abgent_web database.sql mysqldump -uuser -ppassword ltden_db --s ...