codeforce round #467(div.2)
A. Olympiad
给出n个数,让你找出有几个非零并且不重复的数
所以用stl的set
//#define debug #include<stdio.h> #include<math.h> #include<cmath> #include<queue> #include<stack> #include<string> #include<cstring> #include<string.h> #include<algorithm> #include<iostream> #include<vector> #include<functional> #include<iomanip> #include<map> #include<set> #define pb push_back using namespace std; typedef long long ll; pair<ll,ll>PLL; pair<int,ll>Pil; const ll INF = 0x3f3f3f3f; const double inf=1e8+100; const ll maxn =1e5+100; const int N = 1e4+10; const ll mod=1000007; int n,a[maxn]; set<int>s; set<int>::iterator it; void solve() { int i,j,t=1; // cin>>t; while(t--){ cin>>n; while(n--){ int so; cin>>so; if(so>0) s.insert(so); } cout<<s.size()<<endl; s.clear(); } } int main() { ios_base::sync_with_stdio(false); #ifdef debug freopen("in.txt", "r", stdin); freopen("out.txt","w",stdout); #endif cin.tie(0); cout.tie(0); solve(); #ifdef debug fclose(stdin); fclose(stdout); system("out.txt"); #endif return 0; }
B. Vile Grasshoppers
给定一个[p,y]区间,找出其中最大的素数
#define debug #include<stdio.h> #include<math.h> #include<cmath> #include<queue> #include<stack> #include<string> #include<cstring> #include<string.h> #include<algorithm> #include<iostream> #include<vector> #include<functional> #include<iomanip> #include<map> #include<set> #define pb push_back using namespace std; typedef long long ll; pair<ll,ll>PLL; pair<int,ll>Pil; const ll INF = 0x3f3f3f3f; const double inf=1e8+100; const ll maxn =1e5+100; const int N = 1e4+10; const ll mod=1000007; int p,y; bool prime(int x) { for(int i=2; i*i<=x&&i<=p; i++) { if(x%i==0) return 0; } return 1; } void solve() { int i,j,t=1; // cin>>t; while(t--) { cin >> p >> y; for(i=y; i>p; i--) { if(prime(i)) { cout<<i<< endl; return; } } cout <<-1<< endl; } } int main() { ios_base::sync_with_stdio(false); #ifdef debug freopen("in.txt", "r", stdin); freopen("out.txt","w",stdout); #endif cin.tie(0); cout.tie(0); solve(); #ifdef debug fclose(stdin); fclose(stdout); system("out.txt"); #endif return 0; }
C. Save Energy!
一个炉子打开可以烧k时间,julia每d时间去厨房看一趟,一只鸡在炉子一直在烧的时候,烧熟需要t时间,否则需要2t
分析:实际上可以用时间来代表一只鸡烧熟需要的能量(2*t),所以炉子开着时产生的能量就为2*k,因此当
①k%d==0时,所花的时间就为t
②k%d!=0时,我们需要求一次循环的时间:d=(k/d+1)*d(包含k时间);循环的能量:circle=2*k+d-k;循环几次:ans=2*t/circle;剩余能量:t=2*t%circle。最后判断剩余的能量在哪一个位子:(I)t/2<=k,ans=ans*d+t/2 (II)t/2>k,ans=ans*d+k+t-2*k(设最后一段所需要的时间为tt,则t=tt-k+2*k即tt=t+k-2*k)
#define debug #include<stdio.h> #include<math.h> #include<cmath> #include<queue> #include<stack> #include<string> #include<cstring> #include<string.h> #include<algorithm> #include<iostream> #include<vector> #include<functional> #include<iomanip> #include<map> #include<set> #define pb push_back using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll>PLL; typedef pair<int,ll>Pil; const ll INF = 0x3f3f3f3f; const double inf=1e8+100; const ll maxn =1e4+100; const int N = 1e4+10; const ll mod=1000007; const int ml=1e6; ll k,d,t,ans=0; void solve() { int i,j,tt=1; // cin>>t; while(tt--){ ll x; cin>>k>>d>>t; if(k%d==0){ cout<<t<<endl; } else{ d=(k/d+1)*d; t*=2; x=d+k; ans=(t/x)*d; t%=x; if(t<=2*k){ cout<<fixed<<setprecision(2)<<(double)ans+t*0.5<<endl; } else{ t-=2*k; ans+=k; cout<<ans+t<<endl; } } } } int main() { ios_base::sync_with_stdio(false); #ifdef debug freopen("in.txt", "r", stdin); // freopen("out.txt","w",stdout); #endif cin.tie(0); cout.tie(0); solve(); #ifdef debug fclose(stdin); fclose(stdout); system("out.txt"); #endif return 0; }