Noip Simulation Game #38

Source: Internet
Author: User

I opened the #39 problem ... Thought for half an hour more found that I can not write a problem ... So I opened the #38 problem.

T1: The circular number is defined as being able to divide the number into segments of the same length and all the same. N=2e18.

= I will only be 70% violent ...

Positive solution:

The number of loops in [l,r] can be considered as the number of circular integers in [1,r] minus the number of loops in [1,L-1].

For a cyclic integer that determines the length of the loop and the length of the number n, the number in [1,x] can be calculated with the max{x Div k-10^ (i-1) +1,0}, where K is i-1 0, a 1, and the number of times the loop n div I gains.

For example, if you want a number with a length of 6 in [1,666666] with a circular section length of 3, you only need to use 666666 div 1001-100+1=567. This allows you to quickly calculate the number of numbers. This formula is formed when and only if the number length of x equals N. In other words [1,666666] The length of the circular section length of 5 is equal to 99999 div 11111-1+1=9.666666 cannot be used as a dividend.

So you can enumerate the length of the loop section and the length of the number, using the above formula to calculate the number of circular integers.

However, it is easy to see that this practice can cause repeated calculations. Because if the length of the Loop section of an integer is I, then as long as K*i is the number of digits, k*i is also the length of the circular section of the integer, so each time the loop length of the cycle is calculated as the number of loops of I, all the valid cyclic integers of the circular section length I are subtracted.

That is, 9999 in the length of the loop section is 1 when the time has been calculated, and the loop length of 2 is also counted once, so subtract.

The time complexity is O (t* (lgmax{r}) ^2), which is expected to score 100%.

#include <cstdio> #include <cstring> #include <cctype> #include <algorithm>using namespace std; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) #define CLR (x,c) memset (X,c, sizeof (x)) int read () {int X=0;char C=getchar (), while (!isdigit (c)) C=getchar (), while (IsDigit (c)) x=x*10+c-' 0 ', c= GetChar (); return x;} const int Nmax=2e6+5;const int Inf=0x7f7f7f7f;int a[nmax],be[10];bool PD (int x) {int cnt=0;while (x) be[++cnt]=x%10,x/=10 ; if (cnt%2| | cnt==2) {Rep (i,2,cnt) if (Be[i]!=be[i-1]) return 0;return 1;} Else{if (cnt==4) {if (be[1]==be[3]&&be[2]==be[4]) return 1;return 0;} Else{if (Be[1]==be[3]&&be[1]==be[5]&&be[2]==be[4]&&be[2]==be[6]) return 1;if (Be[1]==be[4] &AMP;&AMP;BE[2]==BE[5]&AMP;&AMP;BE[3]==BE[6]) return 1;return 0;}} int main () {freopen ("circulate.in", "R", stdin), Freopen ("Circulate.out", "w", stdout); Rep (i,11,nmax-1) a[i]=a[i-1]+pd (i); int n=read (), U,v;rep (i,1,n) {u=read (), V=read ();p rintf ("%d\n", A[v]-a[u-1]);} Fclose (stdin); fclose (stdout); return 0;} 

T2: The number of strict monotonically increasing or strictly monotonically decreasing sequence of length n. Number of series [1,n]. n=1e6+5;mod=2e6+3;

The rules can be found by playing the table. Ans=c (n-1,n-1-n+1) +c (n,n-n+1) + +c (2*n-2,2*n-2-n+1). Ans=ans*2-n. After seeing this, the linear inverse element can be obtained.

Positive solution:

We can imagine that if we want the number of columns not to increment or decrement (regardless of the case of only one number) then you can select some number to reorder, so it is a combinatorial problem, not a permutation problem.

Then we can put the I-baffle in the n-1 empty, the position that does not have the baffle to represent its adjacent two number equal.

such as 1/2,2,2/3, is a only put 2 baffle sequence, so we can in the number of n-1 to take I position to put the bezel, and then from the number of N out I put in Ans=sigma{c (n-1,i-1) *c (n,i), 1<=i<=n}, Since the two combinations determine one parameter and the other is almost always needed, we can use recursion.

C (n,0) = 1; C (n,i) =c (n,i-1) * (n-i) div (i+1) So you can hand out all C (N,i), C (n-1,i)

Due to the redundancy operation, we can use inverse element to implement Div.

The time complexity is O (NLOGN), the desired score is 100%.

Good god ...

#include <cstdio> #include <cstring> #include <cctype> #include <algorithm>using namespace std; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) #define CLR (x,c) memset (X,c, sizeof (x)) #define LL Long Longint read () {int X=0;char C=getchar (), while (!isdigit (c)) C=getchar (), while (IsDigit (c)) x=x *10+c-' 0 ', C=getchar (); return x;} the const int NMAX=2E6+5;CONST int INF=0X7F7F7F7F;CONST int mod=2e6+3;int inv[mod+1],fac[nmax];int main () {Freopen (" Array.in "," R ", stdin); Freopen (" Array.out "," w ", stdout); Inv[1]=1;rep (I,2,mod) inv[i]=1ll* (mod-mod/i) *inv[mod%i]% Mod;int N=read (); Fac[1]=1;rep (i,2,n+n) fac[i]=1ll*fac[i-1]*i%mod;int ans=1;rep (i,2,n) ans= (ans+1ll*fac[n+i-2]*inv[ Fac[i-1]]%mod*inv[fac[n-1]]%mod)%mod;printf ("%d\n", (ans+ans-n+mod)%mod); fclose (stdin); fclose (stdout); return 0;}

T3: Gives a sequence of length n. Number in the series [1,n]. The maximum number of rigid ascending sequences with a length of 3.

= Think, think, think ... Think of his nature when suddenly think of the size of the number is useless ... The key is to count how many each number is behind. and then greedy. Try to get to those numbers first. Then get three hands to sweep it.

#include <cstdio> #include <cstring> #include <cctype> #include <algorithm>using namespace std; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) #define CLR (x,c) memset (X,c, sizeof (x)) int read () {int X=0;char C=getchar (), while (!isdigit (c)) C=getchar (), while (IsDigit (c)) x=x*10+c-' 0 ', c= GetChar (); return x;} const int Nmax=3e6+5;const int Inf=0x7f7f7f7f;int a[nmax];int vis[nmax];int main () {freopen ("cakes.in", "R", stdin); Freopen ("Cakes.out", "w", stdout); int n=read (), U,cnt=0;rep (i,1,n) {u=read (); if (!vis[u]) vis[u]=++cnt;a[vis[u]]++;} Sort (a+1,a+cnt+1);//rep (i,1,cnt) printf ("%d", A[i]);p rintf ("\ n"); int Ca=cnt-2,cb=cnt-1,cc=cnt,ans=0,tmp;while (ca &GT;0&AMP;&AMP;CB&GT;0&AMP;&AMP;CC&GT;0&AMP;&AMP;CA&LT;CB&AMP;&AMP;CB&LT;CC) {//printf ("%d%d%d\n", ca,cb,cc); + + Ans;--a[ca];--a[cb];--a[cc];if (!A[CC]) {tmp=cb,cb=ca,--ca,cc=tmp;if (!a[cc]) tmp=cb,cb=ca,--ca,cc=tmp;if (!A[CC]) Tmp=cb,cb=ca,--ca,cc=tmp;} if (!A[CB]) {cb=ca,--ca;if (!A[CB]) Cb=ca,--CA;} if (!a[ca])--cA;} printf ("%d\n", ans); fclose (stdin); fclose (stdout); return 0;} /*61 2 3 4 3 261 1 1 2 2 3121 1 2 5 8 2 2 2 3 3 3 1 3*/

Noip Simulation #38

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.