CodeforcesRound #203 (Div.2) fruit 3

Source: Internet
Author: User
CodeforcesRound #203 (Div.2) has handed in C at the last millennium, or else it will drop rating again... B has been knocked on for too long, and the orz encoding capability is insufficient.

Codeforces Round #203 (Div. 2) This game handed in C at the last one, or else it would have to drop rating again... B has been knocked on for too long, and the orz encoding capability is insufficient.

Codeforces Round #203 (Div. 2)

In the end, he handed in C, or else he would drop rating again...

I 've been typing B for too long, and the orz encoding capability is insufficient ~

A-TL

The time limit of the Programming Competition can make the correct answer pass, the wrong answer can not pass, and at least one correct answer can be less than half of the time limit.

Simulate a water question and read the question for a long time ..

Code:

/**  Author:      illuz 
 
  *  Blog:        http://blog.csdn.net/hcbbt*  File:        a.cpp*  Create Date: 2013-10-01 23:38:47*  Descripton:  a */#include 
  
   #include 
   
    using namespace std;#define rep(i, n) for (int i = 0; i < (n); i++)int main() {int n, m, Mina = 100, Maxa = 0, Minb = 100, t;cin >> n >> m;rep(i, n) {cin >> t;Mina = min(Mina, t);Maxa = max(Maxa, t);}rep(i, m) {cin >> t;Minb = min(Minb, t);}if (Mina * 2 >= Minb || Minb <= Maxa) {puts("-1");return 0;}cout << max(Mina * 2, Maxa) << endl;return 0;}
   
  
 


B-Resort

Find the longest route to the hotel. Note that there must be no forks on the road and the road is backward.

Direct dfs + pruning on the line, the graph is saved with set... Look at others using a one-dimensional array.

Code:

/**  Author:      illuz 
 
  *  Blog:        http://blog.csdn.net/hcbbt*  File:        b.cpp*  Create Date: 2013-10-02 00:17:29*  Descripton:  b */#include 
  
   #include 
   
    #include 
    
     #include 
     
      #include using namespace std;#define rep(i, n) for (int i = 0; i < (n); i++)#define repf(i, a, b) for (int i = (a); i <= (b); i++)#define ms(a, i) memset(a, i, sizeof(a))#define FI(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)const int MAXN = 100010;set
      
        pre[MAXN], nex[MAXN];int n, t, obj[MAXN], path[MAXN];int d[MAXN], used[MAXN];int Max = 0, rec;int dp(int o) {if (d[o] != -1) return d[o];if (nex[o].size() > 1 || used[o]) return d[o] = 0;if (pre[o].size() == 0) {path[o] = 0;return d[o] = 1;}d[o] = 0;used[o] = 1;FI(i, pre[o]) {int ts = dp(*i);if (ts > d[o]) {d[o] = ts;path[o] = *i;}}return d[o] + 1;}void F(int p, int cnt) {if (p == 0) return;F(path[p], cnt + 1);if (cnt) printf("%d ", p);else printf("%d\n", p);}int main() {ms(d, -1);scanf("%d", &n);rep(i, n) {scanf("%d", &obj[i + 1]);}rep(i, n) {scanf("%d", &t);if (t) {pre[i + 1].insert(t);nex[t].insert(i + 1);}}repf(i, 1, n) if (obj[i]) {t = dp(i);if (Max < t) {Max = t;rec = i;}}cout << Max << endl;F(rec, 0);return 0;}
      
     
    
   
  
 


C-Bombs

Mine A number of mines and dig them back to the origin to blow them up.

It was nearly empty when I made question B. For more than 20 minutes, I had a chat on qq. I was bored to come and look at question c. I found it a big problem...

Output in the descending order of distance.

Code:

/**  Author:      illuz 
 
  *  Blog:        http://blog.csdn.net/hcbbt*  File:        c.cpp*  Create Date: 2013-10-02 01:14:06*  Descripton:  c */#include 
  
   #include 
   
    #include using namespace std;#define rep(i, n) for (int i = 0; i < (n); i++)typedef long long LL;const int MAXN = 100010;struct P {int x, y;int step;} p[MAXN];int n;bool cmp(P a, P b) {return a.step < b.step;}int main() {cin >> n;LL cnt = 0;rep(i, n) {scanf("%d%d", &p[i].x, &p[i].y); p[i].step = abs(p[i].x) + abs(p[i].y);if (p[i].x) cnt+= 2;if (p[i].y) cnt+=2;cnt += 2;}sort (p, p + n, cmp);cout << cnt << endl;rep(i, n) {if (p[i].x > 0)printf("1 %d R\n", p[i].x);else if (p[i].x < 0)printf("1 %d L\n", -p[i].x);if (p[i].y > 0)printf("1 %d U\n", p[i].y);else if (p[i].y < 0)printf("1 %d D\n", -p[i].y);printf("2\n");if (p[i].x > 0)printf("1 %d L\n", p[i].x);else if (p[i].x < 0)printf("1 %d R\n", -p[i].x);if (p[i].y > 0)printf("1 %d D\n", p[i].y);else if (p[i].y < 0)printf("1 %d U\n", -p[i].y);printf("3\n");}return 0;}
   
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.