注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Minary_Acdream

http://f10.moe/

 
 
 

日志

 
 

Codeforces Round #131 (Div. 2) B. Hometask  

2012-07-31 12:25:24|  分类: CodeForces |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
这题卡了我很久,在比赛结束之前还是没有AC.
直到今天早上看数据的时候才发现自己题目理解错误。
先放题目:

B. Hometask
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?

You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 235 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.

Each digit is allowed to occur in the number the same number of times it occurs in the set.

Input

A single line contains a single integer n (1?≤?n?≤?100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.

Output

On a single line print the answer to the problem. If such number does not exist, then you should print -1.

Sample test(s)
input
1
0
output
0
input
11
3 4 5 4 5 3 5 3 4 4 0
output
5554443330
input
8
3 2 5 1 5 2 2 3
output
-1
Note

In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number.


下面是AC代码:


#include<iostream>
#include<string>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;

int N,n[100010],sum = 0;

bool cmp(int a,int b)
{
return a>b;
}

void deal(int a,int b,int c,int d,int e,int f)
{
int temp = 0;
for(int i = N - 1;i >= 0;i --)
{
if(n[i] == a || n[i] == b || n[i] == c)
{
n[i] = -1;
temp = 1;
break;
}
}
if(temp == 0) {
int temp1 = 0;
for(int i = N - 1;i >= 0;i --){
if(temp1 == 1) break;
if(n[i] == d || n[i] == e || n[i] == f){
for(int j = i - 1;j >= 0;j --){
if(temp1 == 1) break;
if(n[j] == d || n[j] == e || n[j] == f)
{n[j] = -1;n[i] = -1;temp1 = 1;}
}
}
}
}
}

void print()
{
int sum1 = 0;
for(int i = 0;i < N;i ++) if(n[i] != -1) sum1 = sum1 + n[i];

if(sum1 % 3 == 0 && sum1 != 0)
{
for(int j = 0;j < N;j ++)
if(n[j] != -1) cout<<n[j];
cout<<endl;
}
else
{
if(sum1 == 0) cout<<"0"<<endl;
}
}

int main()
{
cin>>N;
for(int i = 0;i < N;i ++)
{
scanf("%d",&n[i]);
}
sort(n,n + N,cmp);
if(N == 1 && n[0] == 0)
{
cout<<"0"<<endl;
}
else
{
if(n[N - 1] != 0) cout<<"-1"<<endl;
else
{
for(int j = 0;j < N;j ++) sum = sum + n[j];
if(sum % 3 == 0)
{
if(n[0] == 0) {cout<<"0"<<endl;}
else
{
for(int i = 0;i < N;i ++) cout<<n[i];
cout<<endl;
}
}
if(sum % 3 == 1)
{
deal(1,4,7,2,5,8);
print();
}
if(sum % 3 == 2)
{
deal(2,5,8,1,4,7);
print();
}
}
}
return 0;
}




然后。。下面的内容完全是自己检讨,赶时间的孩子直接略过吧。
下面就是卡住的地方了:
第6组数据:
12
3 1 2 3 2 0 2 2 2 0 2 3 
Output
3332222220 
Answer
33322222200
应该输出33322222200,我少输了个0.
英语不好的弱菜表示,原先以为是=。 =有多个0存在时只输出一个0,还特意去对0做了下处理。。。
第9组:
Test: #9, time: 10 ms., memory: 1828 KB, exit code: 0, checker exit code: 1, verdict: WRONG_ANSWER
Input
11 3 9 9 6 4 3 6 4 9 6 0 
Output
99966644330 
Answer
999666330 
Checker Log
wrong answer expected 999666330, found 99966644330
在考虑特殊情况的时候没有考虑(1,1),(4,4),(7,7)这样的组合。
粗心的娃伤不起啊。

第65组:
Test: #65, time: 10 ms., memory: 1828 KB, exit code: 0, checker exit code: 1, verdict: WRONG_ANSWER
Input
8 3 3 3 5 5 0 0 0 
Output
0 
Answer
333000 
Checker Log
wrong answer expected 333000, found 0

这组排完序后是5533300,在一次遍历后变成了-1-13300,=。 =一开始没处理好就输出了0.

饿死了。。吃饭去了。
  评论这张
 
阅读(222)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018