[Puzzle + Summary]20150913

Source: Internet
Author: User

1. Preface

I was finally in a mood to write a summary. In fact, this is not good ... Seemingly summed up did not test good is more important, but I think it is because of some 7788 of the reasons for the cause of ... However, the gap is still very big. These days have been tested many times NOIP simulation problem, said is a simulation problem, but in fact every day the difficulty changes are relatively large, some knowledge points also obviously related to the difficulty of the selection of the province. Today feeling is more moderate difficulty, can be slightly simple, because there is no data structure of this code, most of the algorithm used is not much, but still a bit of value.

2, Sum sum

Probably test instructions: (1^B+2^B+...+A^B) mod 10000.

Summary: Although this one eye know is the fast power, but of course not enough, because a,b<=10^9, obviously O (n) are very reluctant. After one exam, Zzd immediately felt his brain pumping. MoD 10000 is not for fun! It is easy to see that, in the sense of modulus, x^b= (x+10000) ^b. So the actual range of operations is n<=10000, and then directly on the basis of a multiplier on the line.

Solving the puzzle: fast Power + optimization

Code:

-------------------------------------------------------------------------------------------------------

#include <cstdio>
#define MOD 10000

typedef long Long LL;

ll N,k,ans,t,lans;

inline ll Pow (ll A,ll b)
{
ll Base=a,ans=1;
while (b)
{
if (b&1) (ans*=base)%=mod;
(base*=base)%=mod;
b>>=1;
}
return ans;
}

int main ()
{
freopen ("sum.in", "R", stdin);
freopen ("Sum.out", "w", stdout);
scanf ("%d", &t);
While (t--)
{
scanf ("%i64d%i64d", &n,&k);
ll Ans=0,x=n/mod,m=n%mod;
for (int i=1;i<=10000;i++)
{
(Ans+=pow (i,k))%=mod;
if (i==m) Lans=ans;
}
(((ans*=x)%=mod) +=lans)%=mod;
printf ("%i64d\n", ans);
}
return 0;
}

-------------------------------------------------------------------------------------------------------

3. Sequence Sequence Merging

Approximate test instructions: give two sequence of length n, in the two times each take 1 number to make a new number, a total of n^2, find the smallest n.

Summary: Seems to have done before? The first time do not seem to heap, think for a long time how to greedy. Now it seems that the problem is still very bare.

The main puzzle: first from small to large, two sequences are sorted, A[1]+B[1..N] added to the heap, and then based on the top of the heap to add a new number ... Until you get the n number.

4, Tower selection coordinates

Approximate test instructions: There are n points on the plane, and the cost of moving a point is the original position and the Manhattan distance of the new location. The minimum cost of K (K∈[1,n]) points in the same position.

Summary: The data range is small let me think this algorithm must be extraordinary. Although we are not sure that every time the selected store must be on the existing point, but actually think it can be found that it must be in all a bit of the horizontal axis, the ordinate is also, so the enumeration of known coordinates is OK, because obviously on a 10^6 map enumeration is not feasible.

Code:

-------------------------------------------------------------------------------------------------------

#include <cstdio>
#include <cstring>
#include <algorithm>

#define MAXN 55
#define INF 0x3f3f3f3f
Using Std::sort;

int min (int a,int b) {return a<b?a:b;}

int abs (int x) {return x<0?-x:x;}

struct POINT
{
int x, y;
};
Point A[MAXN];

int N,ANS[MAXN],DIS[MAXN];

int main ()
{
freopen ("tower.in", "R", stdin);
freopen ("Tower.out", "w", stdout);
scanf ("%d", &n);
for (int i=1;i<=n;i++) scanf ("%d%d", &a[i].x,&a[i].y);
memset (ans,inf,sizeof (ans));
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
{
for (int k=1;k<=n;k++) dis[k]=abs (a[k].x-a[i].x) +abs (A[K].Y-A[J].Y);
sort (dis+1,dis+n+1);
int o=0;
for (int k=1;k<=n;k++) o+=dis[k],ans[k]=min (O,ans[k]);
}
for (int i=1;i<=n;i++) printf ("%d\n", Ans[i]);
return 0;
}

-------------------------------------------------------------------------------------------------------

5. Binary binary binary

Probably test instructions: give three number a,b,c binary, set three maximum length for L, now need to construct three x x, Y, Z, required to meet: their binary form length is not more than the number of L;a 1 is the same, the number of 1 in B is the same as Y, and the number of 1 in C is the same as Z; x+y=z. To find the smallest Z.

Summary: O (n^2 log n) preprocessing the number of lengths and 1, then O (n^2) to judge, scored 40 points. Yet there is another form of violence that can get 50 points. Well, none of this matters.

Solving: Digital DP.

Code (from ZZD):

------------------------------------------------------------------------------------------------------

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

#define LY (P) freopen (P ". In", "R", stdin); Freopen (P ". Out", "w", stdout)
#define LL Long Long
#ifdef WIN32
#define L_L "%i64d"
#else
#define L_L "%lld"
#endif
using namespace Std;
int n, at, BT, CT, T;
LL A, B, C, INF (1LL << 40);
LL f[35][2][35][35][35];

void Upd (ll &a, LL x) {a = min (x, a);}

void work (int w, int t, int j, int k, int l) {
LL now = f[w][t][j][k][l];
for (int x = 0; x <= 1; × x + +)
for (int y = 0; y <= 1; y++)
if (j + x <= at && k + y <= bt)
if (L + ((t + x + y) & 1) <= CT)
UPD (f[w + 1][(t + x + y) >> 1][j + x][k + y][l + ((t + x + y) & 1)], now + (x << W) + (y << w));
}

int Calc (LL a) {
int len (0), CNT (0);
while (a) {
Len + +;
if (A & 1) CNT + +;
a >>= 1;
}
return n = max (len, N), CNT;
}

int main ()
{
LY ("binary");
scanf ("%d", &t);
while (T--) {
scanf (l_l l_l l_l, &a, &b, &c);

n = 0;
at = Calc (A), BT = Calc (B), CT = calc (C);

for (int i = 0; I <= n + 1; i++)
for (int t = 0; t <= 1; t++)
For (int j = 0; J <= in; j + +)
for (int k = 0; k <= bt; k++)
for (int l = 0; l <= ct; l++)
f[i][t][j][k][l] = inf;
f[0][0][0][0][0] = 0;
for (int i = 0; i < n; i++)
for (int t = 0; t <= 1; t++)
For (int j = 0; J <= in; j + +)
for (int k = 0; k <= bt; k++)
for (int l = 0; l <= ct; l++)
if (f[i][t][j][k][l]! = INF)
Work (I, T, J, K, l);

printf (l_l "\ n", f[n][0][at][bt][ct] = = inf -1:f[n][0][at][bt][ct]);
}
return 0;
}

------------------------------------------------------------------------------------------------------

[Puzzle + Summary]20150913

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.