2012-2013 ACM-ICPC Northeastern European Regional Contest (NEERC 12)

Problems
 
 
#Name  
A
addictive.in / addictive.out
2 s, 256 MB
Submit Add to favourites  x438
B
standard input/output
2 s, 256 MB
Submit Add to favourites  x124
C
caravan.in / caravan.out
2 s, 256 MB
Submit Add to favourites  x178
D
disjoint.in / disjoint.out
2 s, 256 MB
Submit Add to favourites  x34
E
exact.in / exact.out
2 s, 256 MB
Submit Add to favourites  x220
F
folding.in / folding.out
2 s, 256 MB
Submit Add to favourites  x76
G
great.in / great.out
2 s, 256 MB
Submit Add to favourites  x359
H
hyperdrome.in / hyperdrome.out
2 s, 256 MB
Submit Add to favourites  x268
I
identification.in / identification.out
2 s, 256 MB
Submit Add to favourites  x29
J
jumping.in / jumping.out
2 s, 256 MB
Submit Add to favourites  x95
K
kingdom.in / kingdom.out
2 s, 256 MB
Submit Add to favourites  
L
labyrinth.in / labyrinth.out
2 s, 256 MB
Submit Add to favourites  x53

A.构造,水题。

 1 #include <map>
 2 #include <set>
 3 #include <cmath>
 4 #include <queue>
 5 #include <stack>
 6 #include <cstdio>
 7 #include <climits>
 8 #include <cstring>
 9 #include <iostream>
10 #include <algorithm>
11 using namespace std;
12 
13 typedef double DB;
14 typedef long long ll;
15 typedef pair<int, int> PII;
16 
17 #define pb push_back
18 #define MP make_pair
19 #define lson l, m, rt << 1
20 #define rson m + 1, r, rt << 1 | 1
21 #define re freopen("addictive.in", "r", stdin)
22 #define we freopen("addictive.out", "w", stdout)
23 #define FOR(i,x,y) for(i=x;i<=y;i++)
24 #define FORD(i,x,y) for(i=x;
25 #define REP(i,x) for(i=0;i<x;i++)
26 #define mf1(x) memset(x,-1,sizeof(x))
27 #define mz(x) memset(x,0,sizeof(x))
28 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
29 
30 const int maxn=12;
31 const int maxm=111111;
32 const int INF=1111111;
33 
34 int h,w,c;
35 int a[maxn];
36 
37 int an[maxn][maxn];
38 
39 void farm(){
40     int i,j,k,l,m;
41     k=1;
42     j=0;
43     l=1;
44     mz(an);
45     REP(i,h){
46         REP(m,w){
47             while(a[l]==0)l++;
48             an[i][j]=l;
49             a[l]--;
50             j+=k;
51         }
52         j-=k;
53         k=-k;
54     }
55 }
56 
57 int main(){
58     re;
59     we;
60     int i,j;
61     while(RD3(h,w,c)!=EOF){
62         FOR(i,1,c)scanf("%d",&a[i]);
63         farm();
64         REP(i,h){
65             REP(j,w)printf("%d",an[i][j]);
66             puts("");
67         }
68     }
69 }
View Code

 

C.long double二分答案,最后枚举分母找一个分子。

 1 //#pragma comment(linker, "/STACK:102400000,102400000")
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<iostream>
 5 #include<cstring>
 6 #include<algorithm>
 7 #include<cmath>
 8 #include<map>
 9 #include<set>
10 #include<stack>
11 #include<queue>
12 using namespace std;
13 #define mz(array) memset(array, 0, sizeof(array))
14 #define mf1(array) memset(array, -1, sizeof(array))
15 #define minf(array) memset(array, 0x3f, sizeof(array))
16 #define REP(i,n) for(i=0;i<(n);i++)
17 #define FOR(i,x,n) for(i=(x);i<=(n);i++)
18 #define RD(x) scanf("%d",&x)
19 #define RD2(x,y) scanf("%d%d",&x,&y)
20 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
21 #define WN(x) printf("%d\n",x);
22 #define RE  freopen("caravan.in","r",stdin)
23 #define WE  freopen("caravan.out","w",stdout)
24 #define mp make_pair
25 #define pb push_back
26 #define pf push_front
27 #define ppf pop_front
28 #define ppb pop_back
29 typedef long long ll;
30 typedef unsigned long long ull;
31 typedef long double LD;
32 
33 const LD pi=acos(-1.0);
34 const LD eps=1e-13;
35 
36 const int maxn=111111;
37 
38 struct qj{
39     int l,r;
40 }a[maxn];
41 
42 bool cmp(qj x, qj y){
43     return x.l < y.l;
44 }
45 
46 int n;
47 
48 int ans0,ans1;
49 
50 bool ok(LD x){
51     int i;
52     LD y=0.0;
53     REP(i,n){
54         if(a[i].r - x + eps < y)return 0;
55         y = max((LD)a[i].l , y) + x;
56     }
57     return 1;
58 }
59 
60 void farm(){
61     int i;
62     LD l=0.0,r=10000000.0,mid;
63     REP(i,n)r=min(r , (LD)(a[i].r-a[i].l));
64     sort(a,a+n,cmp);
65     while(r-l>eps){
66         mid=(l+r)*0.5;
67         if(ok(mid))l=mid;
68         else r=mid;
69     }
70     LD dou=1.0;
71     FOR(i,1,1000000){
72         if( fabs(r*i - (LD)ceil(r*i))<dou){
73             ans0=ceil(r*i);
74             ans1=i;
75             dou=fabs(r*i - (LD)ceil(r*i));
76         }
77         if( fabs(r*i - (LD)floor(r*i))<dou){
78             ans0=floor(r*i);
79             ans1=i;
80             dou=fabs(r*i - (LD)floor(r*i));
81         }
82     }
83 }
84 
85 int main(){
86     RE;
87     WE;
88     int i;
89     while(scanf("%d",&n)!=EOF){
90         REP(i,n)RD2(a[i].l, a[i].r);
91         farm();
92         printf("%d/%d\n",ans0,ans1);
93     }
94 }
View Code

 

E.贪心,分成19种包,分别按大小排序,要取其中一种肯定是取那种最大的。每次取能处理最低的非零位的最重的包,让它产生尽量多的零。

  1 //#pragma comment(linker, "/STACK:102400000,102400000")
  2 #include<cstdio>
  3 #include<cmath>
  4 #include<iostream>
  5 #include<cstring>
  6 #include<algorithm>
  7 #include<cmath>
  8 #include<map>
  9 #include<set>
 10 #include<stack>
 11 #include<queue>
 12 using namespace std;
 13 #define mz(array) memset(array, 0, sizeof(array))
 14 #define mf1(array) memset(array, -1, sizeof(array))
 15 #define minf(array) memset(array, 0x3f, sizeof(array))
 16 #define REP(i,n) for(i=0;i<(n);i++)
 17 #define FOR(i,x,n) for(i=(x);i<=(n);i++)
 18 #define RD(x) scanf("%d",&x)
 19 #define RD2(x,y) scanf("%d%d",&x,&y)
 20 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
 21 #define WN(x) printf("%d\n",x);
 22 #define RE  freopen("exact.in","r",stdin)
 23 #define WE  freopen("exact.out","w",stdout)
 24 #define mp make_pair
 25 #define pb push_back
 26 #define pf push_front
 27 #define ppf pop_front
 28 #define ppb pop_back
 29 typedef long long ll;
 30 typedef unsigned long long ull;
 31 typedef long double LD;
 32 
 33 const LD pi=acos(-1.0);
 34 const LD eps=1e-13;
 35 
 36 ll X;
 37 int n;
 38 
 39 struct Box {
 40     ll n;
 41     int i;
 42     Box(int _i,ll _n) {
 43         i=_i;
 44         n=_n;
 45     }
 46 };
 47 
 48 bool cmp(Box x, Box y) {
 49     return x.n<y.n;
 50 }
 51 ll ten[22];
 52 vector<Box>a[20];
 53 
 54 vector<int>an;
 55 
 56 
 57 bool farm() {
 58     int i,j,k;
 59     REP(i,20)sort(a[i].begin(),a[i].end(),cmp);
 60     an.clear();
 61     ll x=X;
 62     ll t=0;
 63     k=0;
 64     while(x) {
 65         while(k<=17 && x%ten[k+1]==0)k++;
 66         int mai=-1;
 67         ll ma=0;
 68         //printf("x=%I64d , k=%d\n",x,k);
 69         FOR(i,0,k) {
 70             if(!a[i].empty()) {
 71                 if(a[i].back().n * ten[i] >ma) {
 72                     mai=i;
 73                     ma=a[i].back().n * ten[i];
 74                 }
 75             }
 76         }
 77         if(mai==-1)return 0;
 78         an.pb(a[mai].back().i);
 79         t += a[mai].back().n * ten[mai];
 80         //printf("t=%I64d\n",t);
 81         ll q;
 82         if(x>t){
 83             j=k;
 84             while(x%ten[j+1] <= t)j++;
 85             if(j!=k)q=x%ten[j];
 86             else q=t;
 87         }else q=x;
 88         x-=q;
 89         t-=q;
 90         a[mai].pop_back();
 91     }
 92     return 1;
 93 }
 94 
 95 void init() {
 96     int i;
 97     ten[0]=1;
 98     FOR(i,1,18) {
 99         ten[i]=ten[i-1]*10;
100     }
101     ten[19]=2*ten[18];
102 }
103 
104 int main() {
105     RE;
106     WE;
107     init();
108     int i,x;
109     ll y;
110     while(scanf("%I64d%d",&X,&n)!=EOF) {
111         REP(i,20)a[i].clear();
112         FOR(i,1,n) {
113             scanf("%d%I64d",&x,&y);
114             a[x].pb(Box(i,y));
115         }
116         if(farm()) {
117             printf("%d\n",an.size());
118             if(!an.empty())printf("%d",an[0]);
119             FOR(i,1,an.size()-1)printf(" %d",an[i]);
120             puts("");
121         } else puts("-1");
122     }
123     return 0;
124 }
View Code

 

G.数位DP,写简单点就是记忆化搜索型的。

 1 #include <map>
 2 #include <set>
 3 #include <cmath>
 4 #include <queue>
 5 #include <stack>
 6 #include <cstdio>
 7 #include <climits>
 8 #include <cstring>
 9 #include <iostream>
10 #include <algorithm>
11 using namespace std;
12 
13 typedef double DB;
14 typedef long long ll;
15 typedef pair<int, int> PII;
16 
17 #define pb push_back
18 #define MP make_pair
19 #define lson l, m, rt << 1
20 #define rson m + 1, r, rt << 1 | 1
21 #define RE freopen("great.in", "r", stdin)
22 #define WE freopen("great.out", "w", stdout)
23 #define FOR(i,x,y) for(i=x;i<=y;i++)
24 #define FORD(i,x,y) for(i=x;
25 #define REP(i,x) for(i=0;i<x;i++)
26 #define mf1(x) memset(x,-1,sizeof(x))
27 #define mz(x) memset(x,0,sizeof(x))
28 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
29 
30 const int maxn=100;
31 const int maxm=111111;
32 const int INF=1111111;
33 
34 ll n;
35 int k;
36 
37 ll pow(int x){
38     int i;
39     ll re=1;
40     REP(i,x)re*=k;
41     return re;
42 }
43 
44 int a[maxn];
45 ll f[maxn];
46 
47 ll dfs(int w, bool limit){
48     if(w<0) return 1;
49     if(!limit && f[w]!=-1)return f[w];
50     int maxi=limit?a[w]:k-1;
51     if(w%2==1)maxi=0;
52     ll re=0;
53     int i;
54     FOR(i,0,maxi){
55         re+=dfs(w-1, limit && i==a[w]);
56     }
57     if(!limit)f[w]=re;
58     return re;
59 }
60 
61 ll farm(){
62     ll re=0;
63     ll t=n;
64     ll w=0;
65     ll m=0;
66     int i,j;
67     while(t){
68         a[w]=t%k;
69         t/=k;
70         w++;
71     }
72     mf1(f);
73     return dfs(w-1, 1);
74 }
75 
76 int main(){
77     RE;
78     WE;
79     int i,j;
80     while(scanf("%I64d%d",&n,&k)!=EOF){
81         printf("%I64d\n",farm());
82     }
83 }
View Code

 

H.状压。1~i中各个字母是奇数个还是偶数个,能用2^52种状态表示。状态R xor 状态L,得到的就是区间[L,R]的状态,其中有0个或1个1就是可行的。

用hash存之前出现过的状态,枚举那个唯一的一个1来统计,O(52n)这样。

 

  1 #include <map>
  2 #include <set>
  3 #include <cmath>
  4 #include <queue>
  5 #include <stack>
  6 #include <cstdio>
  7 #include <climits>
  8 #include <cstring>
  9 #include <iostream>
 10 #include <algorithm>
 11 #include <hash_map>
 12 using namespace std;
 13 using namespace stdext;
 14 typedef double DB;
 15 typedef long long ll;
 16 typedef unsigned int usint;
 17 typedef pair<int, int> PII;
 18 
 19 #define pb push_back
 20 #define MP make_pair
 21 #define lson l, m, rt << 1
 22 #define rson m + 1, r, rt << 1 | 1
 23 #define RE freopen("hyperdrome.in", "r", stdin)
 24 #define WE freopen("hyperdrome.out", "w", stdout)
 25 #define FOR(i,x,y) for(i=x;i<=y;i++)
 26 #define FORD(i,x,y) for(i=x;
 27 #define REP(i,x) for(i=0;i<x;i++)
 28 #define mf1(x) memset(x,-1,sizeof(x))
 29 #define mz(x) memset(x,0,sizeof(x))
 30 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
 31 
 32 const int maxn=333333;
 33 const int maxm=111111;
 34 const int INF=1111111;
 35 
 36 char s[maxn];
 37 int q[133];
 38 int n;
 39 ll l[66];
 40 
 41 //hash_map<ll,ll>S;
 42 
 43 const ll NONE=-1;
 44 class hash {
 45 public:
 46     hash() {
 47         memset(a,0xff,sizeof(a));
 48     }
 49     usint locate(ll x) {
 50         usint l=x%MOD;
 51         while(a[l]!=x&&a[l]!=NONE) l=l+1;
 52         return l;
 53     }
 54     void insert(ll x,ll va) {
 55         usint l=locate(x);
 56         if(a[l]==NONE) {
 57             a[l]=x;
 58             v[l]=va;
 59         }
 60     }
 61 
 62     void add(ll x) {
 63         usint l=locate(x);
 64         if(a[l]==NONE) {
 65             a[l]=x;
 66             v[l]=1;
 67         }else{
 68             v[l]++;
 69         }
 70     }
 71 
 72     ll find(ll x) {
 73         usint l=locate(x);
 74         return a[l]==x?v[l]:0;
 75     }
 76     void clear() {
 77         memset(a,-1,sizeof(a));
 78     }
 79 private:
 80     static const usint MOD=1000007;
 81     ll a[MOD+100];
 82     usint v[MOD+100];
 83 } S;
 84 
 85 ll farm(){
 86     int i,j;
 87     ll x=0;
 88     ll re=0;
 89     S.clear();
 90     S.insert(0,1);
 91     REP(i,n){
 92         x^=(l[q[s[i]]]);
 93         FOR(j,0,51){
 94             re+=S.find(x ^ l[j]);
 95         }
 96         re+=S.find(x);
 97         S.add(x);
 98         //printf("%I64d,%I64d,%I64d,%I64d\n",x,S[x],re,1LL<<q[s[i]]);
 99     }
100     return re;
101 }
102 
103 void init(){
104     int i;
105     FOR(i,'a','z')q[i]=i-'a';
106     FOR(i,'A','Z')q[i]=i-'A'+26;
107     FOR(i,0,60)l[i]=1LL<<i;
108 }
109 
110 int main(){
111     RE;
112     WE;
113     int i,j;
114     init();
115     while(scanf("%d",&n)!=EOF){
116         scanf(" %s",s);
117         printf("%I64d\n",farm());
118     }
119 }
View Code

 

posted @ 2014-11-19 18:23  带鱼Yuiffy  阅读(978)  评论(0编辑  收藏  举报