codeforces Round #347 (Div. 2) C - International Olympiad

思路:从后往前一位一位的模拟,每次判断一下当前枚举的数是否之间枚举过了。或者当前枚举数过小,小于1989.

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cstdlib>
 4 #include<iostream>
 5 #include<queue>
 6 #include<stack>
 7 #include<cmath>
 8 #include<algorithm>
 9 #include<malloc.h>
10 using namespace std;
11 #define clc(a,b) memset(a,b,sizeof(a))
12 #define inf 0x3f3f3f3f
13 const int N=10010;
14 #define LL long long
15 const double eps = 1e-5;
16 const double pi = acos(-1);
17 // inline int r(){
18 //     int x=0,f=1;char ch=getchar();
19 //     while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘) f=-1;ch=getchar();}
20 //     while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
21 //     return x*f;
22 // }
23
24 int vis[20];
25 int a[15]={1990,1991,1992,1993,1994,1995,1996,1997,1998,1989};//看成基数数组
26 int main(){
27     int T;
28     scanf("%d",&T);
29     char s[10];
30     while(T--){
31         scanf("%s",s);
32     int len = strlen(s);
33     int bas=s[len-1]-‘0‘;
34     int extra=0;
35     int index=1;
36     int total=0;
37     int cur;
38     for(int i=len-1;s[i]>=‘0‘&&s[i]<=‘9‘;i--){
39         extra+=(s[i]-‘0‘)*index;
40         index*=10;
41         int pre=a[bas]/index-1;
42         bool flag=true;
43         while(flag){
44             pre++;
45             cur=pre*index+extra;
46             if(cur<a[bas]){
47                 continue;
48             }
49             flag=false;
50             for(int j=0;j<total;j++){
51                 if(vis[j]==cur){
52                     flag=true;
53                     break;
54                 }
55             }
56         }
57         vis[total++]=cur;
58     }
59     printf("%d\n",vis[--total]);
60     }
61     return 0;
62 }

时间: 2024-10-23 22:50:30

codeforces Round #347 (Div. 2) C - International Olympiad的相关文章

DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad

题目传送门 1 /* 2 DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <cstring> 7 #include <cmath> 8 #include <algorithm> 9 #include <vector> 10 #include <map> 11 #include

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D

Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process. There are n + 1 cities consecutively num

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A. Fraction

题意:2个数A,B,A+B==n,并且A<B,问最大的A/B是多少,A与B互质 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+100; 4 typedef long long ll; 5 6 7 int main(){ 8 int n; 9 cin>>n; 10 for(int i=n/2;i>=1;i--){ 11 int y=n-i; 12 if(__gcd(i,y)==1){

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C. Planning

题意:给出每个航班花费和顺序,求新顺序使得花费最少 思路:肯定是花费最大的先决定,二分一下 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+100; 4 typedef long long ll; 5 6 struct node{ 7 ll x; 8 int id; 9 ll yy; 10 }a[300004]; 11 bool cmp(node p,node q){ 12 return p.x>q.x

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) B. Maxim Buys an Apartment

题意:有n个房子,k个有人住,问最少有多个,最多有多少个好的房子,好的房子定义:周围最少有一个房子有人住 思路:我们可以知道一个住了人的房子他最多产生2个好的房子(左右)所以判断k*3是否>=n 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+100; 4 typedef long long ll; 5 6 7 int main(){ 8 ll n,k; 9 cin>>n>>k;

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A

Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction  is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its numerator

Codeforces Round #279 (Div. 2) A. Team Olympiad 水题

#include<stdio.h> #include<iostream> #include<memory.h> #include<math.h> using namespace std; int flag1[5000]; int flag2[5000]; int flag3[5000]; int main() { memset(flag1,0,sizeof(flag1)); memset(flag2,0,sizeof(flag2)); memset(flag

【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) A】Palindrome Dance

[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] i从1..n/2循环一波. 保证a[i]和a[n-i+1]就好. 如果都是2的话填上min(a,b)*2就好 其他情况跟随非2的. [代码] #include <bits/stdc++.h> #define LL long long #define rep1(i,a,b) for (int i = a;i <= b;i++) #define rep2(i,a,b) for (int i = a;i >= b;i--

Codeforces Round #516 (Div. 2, by Moscow Team Olympiad)

Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) https://codeforces.com/contest/1064 A 1 #include<bits/stdc++.h> 2 #define pb push_back 3 using namespace std; 4 5 bool Check(int a,int b,int c){ 6 if(a+b>c&&b+c>a&&a+c>