UPC 2017 Summer Training 6 A,D,I

来源:互联网 发布:b超数据算胎儿体重公式 编辑:程序博客网 时间:2024/05/18 02:20

A. Anagrams
time limit per test
1.0 s
memory limit per test
512 MB
input
standard input
output
standard output

Consider the positional numeral system with a given base b. A positive integer x is called b-anagram of a positive integer y if they have the same length of representation in this system (without leading zeroes) and y can be obtained by rearranging the digits of x.

A positive integer k is called b-stable if for every integer m that is divisible by k all its b-anagrams are also divisible by k. Your task is to find all b-stable integers k for a given base b.

Input

The only line of the input contains an integer b — the base of the given positional numeral system (2 ≤ b ≤ 2·109).

Output

Print all b-stable integers k represented in the standard decimal numeral system. They must be printed in ascending order.

Examples
input
3
output
1 2
input
9
output
1 2 4 8
input
33
output
1 2 4 8 16 32

123

题意:给定进制b, 在b进制下, 满足k的倍数的x 有相同长度 的y   又能被k 整除 这样所有的数

理解为 b-1 的因子:

#include <iostream>#include <stdio.h>#include <algorithm>#include <cmath>#include <cstring>#include <string>#include <queue>#include <stack>#include <set>#include <bitset>#include <vector>using namespace std;typedef long long ll;const double PI=acos(-1);const int INF=0x3f3f3f3f;const double esp=1e-4;const int maxn=10000005;const int MOD=1e9+7;const int N=100000000;#define mem(a,b) memset(a,b,sizeof(a))ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}ll n;void solve(){vector<ll> a;int cont=0;for(ll i=1;i<=n;i++){if(n / i < i) break;        if(n%i==0){          a.push_back(i);        if(n/i!=i)          a.push_back(n/i);        }}sort(a.begin(),a.end());int len=a.size();for(int i=0;i<len;i++){if(i==0)printf("%lld",a[i]);elseprintf(" %lld",a[i]);}cout<<endl;}int main(){//iinit();while(~scanf("%lld",&n)){n-=1;solve();}}

D-Delay Time

 求磁铁的时间延迟;

暴力;

#include <iostream>#include <stdio.h>#include <algorithm>#include <cmath>#include <cstring>#include <string>#include <queue>#include <stack>#include <set>#include <bitset>#include <vector>using namespace std;typedef long long ll;const double PI=acos(-1);const int INF=0x3f3f3f3f;const double esp=1e-4;const int maxn=10000005;const int MOD=1e9+7;#define mem(a,b) memset(a,b,sizeof(a))ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}double h1,t1,h2,t2;double fuck(double x){double T1,T2;T1=t1-x;T2=t2-x;double g1,g2;g1=2*h1/(T1*T1);g2=2*h2/(T2*T2);return fabs(g1-g2);}int main(){scanf("%lf %lf",&h1,&t1);scanf("%lf %lf",&h2,&t2);        double le=0.0,ri=min(t1,t2);    double ans=0.0,MAX=INF*1.0;    double caonima;    for(double i=le;i<=ri;i+=0.000001){        caonima=fuck(i);        if(caonima<MAX){            MAX=caonima;            ans=i;        }    }    printf("%.6f\n",ans);}

I. Illegal or Not?
time limit per test
1.0 s
memory limit per test
512 MB
input
standard input
output
standard output

The Schengen Agreement was signed by a number of countries to uniform many visa-related questions and to allow tourists from outside of the Schengen area to enter and freely travel within Schengen member states using only one visa. A multiple-entry visa owner can perform many travels to any Schengen member state using a single visa, but migration laws limit the number of days he is allowed to stay there. For any consecutive 180 days a visa owner is only allowed to be inside the Schengen area for no more than 90 days in total.

A tourist has got his 5-year Schengen multiple-entry visa on October 18th 2010, therefore he could travel to and from the Schengen area at any of 5·365 + 1 (2012 was a leap year)  = 1826 days.

Yesterday (October 17th, 2015) was the last day his visa was valid, and the tourist wants to know whether he has broken the migration laws and may face problems with obtaining a new Schengen visa. You are given the information about all trips to the Schengen member states he did using this visa and are to verify the rule about consecutive days for multiple-entry visa holders. According to the Schengen visa rules the day of arrival and the day of departure are considered to be days spent inside the Schengen area.

Input

The first line of the input contains only number of trips n (1 ≤ n ≤ 1826).

The i-th of the following n lines describes the i-th trip with two integers ai and di — the day of arrival to Schengen area and the day of departure respectively (1 ≤ ai ≤ di ≤ 1826). Days are numbered starting from the day the visa was issued.

It is guaranteed that these trips do not overlap, that is, each of 1826 days is a part of no more than one trip. Trips are given in arbitrary order.

Output

Output "Yes" (without quotes) if the tourist has followed the rules and may not worry about a new visa. Print "No" (without quotes) if he needs to start to look for an explanation to give to migration officer.

Examples
input
12 91
output
Yes
input
11 91
output
No
input
23 91180 200
output
No
input
2181 2701 90
output
Yes
Note

In the second sample the tourist was in Schengen area for 91 days in the 180-day window which starts on day 1.

In the third sample the tourist was in Schengen area for 91 days in the 180-day window which started on day 2 (89 days from day 3 to day 91 and 2 days from day 180 to day 181).


连续180的天数内不能超过90 天 ,   题意真难读懂;

暴力:

#include <iostream>#include <stdio.h>#include <algorithm>#include <cmath>#include <cstring>#include <string>#include <queue>#include <stack>#include <set>#include <bitset>#include <vector>using namespace std;typedef long long ll;const double PI=acos(-1);const int INF=0x3f3f3f3f;const double esp=1e-4;const int maxn=10000005;const int MOD=1e9+7;#define mem(a,b) memset(a,b,sizeof(a))ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}int a[100020];int main(){int n;int x,y;while(~scanf("%d",&n)){mem(a,0);for(int i=1;i<=n;i++){scanf("%d %d",&x,&y);for(int i=x;i<=y;i++)a[i]=1;}int cont=0;int flag=0;int k=0;for(int i=0;i<=1826;i++){cont=0;for(int j=i;j<i+180;j++){cont+=a[j];if(cont>90){flag=1;break;}}}if(!flag)printf("Yes\n");elseprintf("No\n");}}