Codeforces Round #250 (Div. 2) A, B, C
1 second
256 megabytes
standard input
standard output
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The child will follow the algorithm:
- If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great.
- If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice).
You are given a multiple-choice questions, can you predict child's choose?
The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length.
Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_".
Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes).
- A.VFleaKing_is_the_author_of_this_problem
B.Picks_is_the_author_of_this_problem
C.Picking_is_the_author_of_this_problem
D.Ftiasch_is_cute
- D
- A.ab
B.abcde
C.ab
D.abc
- C
- A.c
B.cc
C.c
D.c
- B
In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no choice is great, so the child will choose the luckiest choice C.
In the third sample, the choice B (length 2) is twice longer than all other choices', so it is great choice. There is no other great choices so the child will choose B.
题意:四个字符串除去前面的两个字符,长度大于等于其余的两倍,长度小于等于其余的1/2;
如果唯一输出那个选项,否则输出C;
思路:模拟;
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define pi (4*atan(1.0))
- const int N=5e5+,M=4e6+,inf=1e9+;
- int a[];
- char ch[];
- int da,xiao;
- int check()
- {
- int ans=;
- for(int i=;i<=;i++)
- {
- int flag1=,flag2=;
- for(int t=;t<=;t++)
- {
- if(i==t)continue;
- if(a[i]>=*a[t])
- flag1++;
- if(*a[i]<=a[t])
- flag2++;
- }
- if(flag1==)
- ans++,da=i;
- if(flag2==)
- ans++,xiao=i;
- }
- return ans;
- }
- int main()
- {
- int x,y,z,i,t;
- for(i=;i<=;i++)
- {
- scanf("%s",&ch);
- a[i]=strlen(ch)-;
- }
- if(check()==)
- {
- if(da)
- printf("%c\n",'A'+da-);
- else
- printf("%c\n",xiao-+'A');
- }
- else
- printf("C\n");
- return ;
- }
1 second
256 megabytes
standard input
standard output
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S:
- its elements were distinct integers from 1 to limit;
- the value of
was equal to sum; here lowbit(x) equals 2k where k is the position of the first one in the binary representation of x. For example, lowbit(100102) = 102, lowbit(100012) = 12, lowbit(100002) = 100002 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
The first line contains two integers: sum, limit (1 ≤ sum, limit ≤ 105).
In the first line print an integer n (1 ≤ n ≤ 105), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
- 5 5
- 2
4 5
- 4 3
- 3
2 3 1
- 5 1
- -1
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4.
题意:用lowbit(i) 1<=i<=limit;选出一些数的和得到sum;
思路:lowbit函数得到的肯定是2的次方;从大往小减,得到答案,详见代码;
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define pi (4*atan(1.0))
- const int N=5e5+,M=4e6+,inf=1e9+;
- int a[]={,,,,,,,,,,,,,,,,,,,};
- vector<int>v[];
- int flag[];
- int ans[];
- int lowbit(int x)
- {
- return x&-x;
- }
- int main()
- {
- int x,y,z,i,t,len=,base=,sum=;
- scanf("%d%d",&x,&y);
- for(int i=;i<=y;i++)
- v[lower_bound(a,a+,lowbit(i))-a].push_back(i);
- for(i=;i>=;i/=)
- {
- if(x<i)continue;
- int pos=lower_bound(a,a+,i)-a;
- int si=v[pos].size();
- ans[pos]=min(si,x/i);
- sum+=ans[pos];
- x-=ans[pos]*i;
- }
- if(x)
- printf("-1\n");
- else
- {
- printf("%d\n",sum);
- for(i=;i<;i++)
- if(ans[i])
- {
- for(t=;t<ans[i];t++)
- printf("%d ",v[i][t]);
- }
- }
- return ;
- }
1 second
256 megabytes
standard input
standard output
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.
Help the child to find out, what is the minimum total energy he should spend to remove all n parts.
The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn(0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi(1 ≤ xi, yi ≤ n; xi ≠ yi).
Consider all the parts are numbered from 1 to n.
Output the minimum total energy the child should spend to remove all n parts of the toy.
- 4 3
10 20 30 40
1 4
1 2
2 3
- 40
- 4 4
100 100 100 100
1 2
2 3
2 4
3 4
- 400
- 7 10
40 10 20 10 20 80 40
1 5
4 7
4 5
5 2
5 7
6 4
1 6
1 3
4 3
1 4
- 160
One of the optimal sequence of actions in the first sample is:
- First, remove part 3, cost of the action is 20.
- Then, remove part 2, cost of the action is 10.
- Next, remove part 4, cost of the action is 10.
- At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
In the second sample, the child will spend 400 no matter in what order he will remove the parts.
题意:给你一个图,n个点,m条边,每次拆一个点的消耗为与其直接相连的点的权值和吗,求最小的消耗;
思路:贪心,去每条边两点权值最小值即可;
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- //#define mod 1000000007
- #define pi (4*atan(1.0))
- const int N=1e5+,M=1e6+,inf=1e9+;
- int a[N];
- int main()
- {
- int x,y,z,i,t;
- while(~scanf("%d%d",&x,&y))
- {
- for(i=;i<=x;i++)
- scanf("%d",&a[i]);
- ll ans=;
- for(i=;i<=y;i++)
- {
- int u,v;
- scanf("%d%d",&u,&v);
- ans+=min(a[u],a[v]);
- }
- printf("%lld\n",ans);
- }
- return ;
- }
Codeforces Round #250 (Div. 2) A, B, C的更多相关文章
- Codeforces Round #250 (Div. 2)A(英语学习)
链接:http://codeforces.com/contest/437/problem/A A. The Child and Homework time limit per test 1 secon ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence (线段树)
题目链接:http://codeforces.com/problemset/problem/438/D 给你n个数,m个操作,1操作是查询l到r之间的和,2操作是将l到r之间大于等于x的数xor于x, ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸
D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces Round #250 (Div. 1) B. The Child and Zoo 并查集
B. The Child and Zoo Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/ ...
- Codeforces Round #250 (Div. 1) A. The Child and Toy 水题
A. The Child and Toy Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/ ...
- Codeforces Round #250 (Div. 2) A. The Child and Homework
注意题目长度不能考虑前缀,而且如果即存在一个选项的长度的两倍小于其他所有选项的长度,也存在一个选项的长度大于其他选项长度的两倍,则答案不是一个好的选择,只能选择C. #include <iost ...
- Codeforces Round #250 (Div. 2) C、The Child and Toy
注意此题,每一个部分都有一个能量值v[i],他移除第i部分所需的能量是v[f[1]]+v[f[2]]+...+v[f[k]],其中f[1],f[2],...,f[k]是与i直接相连(且还未被移除)的部 ...
- Codeforces Round #250 (Div. 2)
感觉不会再爱了,呜呜! A题原来HACK这么多!很多人跟我一样掉坑了! If there is some choice whose description at least twice shorter ...
- Codeforces Round #250 (Div. 2)——The Child and Set
题目链接 题意: 给定goal和limit,求1-limit中的若干个数,每一个数最多出现一次,且这些数的lowbit()值之和等于goal,假设存在这种一些数,输出个数和每一个数:否则-1 分析: ...
- Codeforces Round #250 (Div. 2)—A. The Child and Homework
好题啊,被HACK了.曾经做题都是人数越来越多.这次比赛 PASS人数 从2000直掉 1000人 被HACK 1000多人! ! ! ! 没见过的科技啊 1 2 4 8 这组数 被黑的 ...
随机推荐
- Hadoop 配置及hadoop HA 的配置
注:本文中提到的ochadoop 不要感到奇怪,是亚信公司内部自己合成的一个包.把全部的组件都放在一个包内了.免去了组件的下载过程和解决兼容问题.事实上也能够自己下载的.不要受到影响. 另,转载请注明 ...
- 在Vue中使用layer.js弹出层插件
layer.js(mobile)是一个小巧方便的弹出层插件,在之前的apicloud项目中被大量使用,但最近对apicloud的IDE.非常不友好的文档和极低的开发效率深感厌烦,决定弃用然后转向Vue ...
- 数据库操作事物的四大特性以及MySQL数据库的四种隔离级别
1 .事物操作数据库的四大特性(ACID) 1.原子性 (Atomicity) 原子性:就是事物的所包含的所有操作,要么全部成功,要么全部失败回滚. 2.一致性 (Consistency) 一致性:简 ...
- java多线程编码注意事项
Sole purpose of using concurrency is to produce scalable and faster program. But always remember, sp ...
- centos6下手工编译vitess
vitess是youtub开源的一款mysql代理,在ubuntu下编译非常方便.可是在centos下且不能訪问google的情况下坑比較多.近期依据其bootstrap.sh脚本手工编译成功.把过程 ...
- hadoop常见算法(持续更新)
1. 对以下数据进行排序,根据收入减去支出得到最后结余从大到小排序 账号 收入 支出 日期 zhangsan@163.com 6000 0 2014-02-20 lisi@163.com 2000 0 ...
- android 国际化 设置
复制了他人的方法 方法和步骤 1 配置选项包括语言代号和地区代号.表示中文和中国的配置选项是 zh-rCN; 表示英文和美国的配置选项是en-rUS.其中,zh 和 en 表示中文和英文: 2 如果想 ...
- csv文件的格式
csv, comma separated values csv是一种纯文本文件. csv文件由任意数目的记录构成,记录间以换行符分割,每条记录由字段构成,字段间以逗号作为分隔符. 如果字段中有逗号,那 ...
- world embedding 嵌入
http://papers.nips.cc/paper/5477-neural-word-embedding-as-implicit-matrix-factorization 嵌入 | Tenso ...
- 【python】-- try except (异常捕获)、断言
try except (异常捕获) 当程序出错了,但是我们又不想让用户看到这个错误,而且我在写程序的时候已经预料到了它可以出现这样的错误,出现这样的错误代表着什么,我们可以提前捕获这些个错误 1.异常 ...