1. 程式人生 > >May Challenge 2017

May Challenge 2017

i++ targe set 技術 pro tin his http display

Chef and his daily routine

分析:水題,設置優先級,判斷如果後面小於前面就輸出no

技術分享
 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "string"
 5 using namespace std;
 6 const int maxn=10000+10;
 7 string s;
 8 int T;
 9 int judge(char s){
10     if(s==C)
11         return 1;
12     else if(s==E)
13         return
2; 14 else 15 return 3; 16 } 17 int main() 18 { 19 cin>>T; 20 while(T--){ 21 cin>>s; 22 int flag=0; 23 int len=s.length(); 24 for(int i=0;i<len-1;i++){ 25 if(judge(s[i])>judge(s[i+1])){ 26 flag=1; break;
27 } 28 } 29 if(flag) cout<<"no"<<endl; 30 else cout<<"yes"<<endl; 31 } 32 }
View Code

Courses in an university

分析:簡單DP,看上一個狀態和當前狀態的關系,如果先修課程數相同,則加1,否則取上一門課程加1和當前課程所需先修的最小值

技術分享
 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring
" 4 #include "string" 5 using namespace std; 6 const int maxn=100000+10; 7 int T; 8 int a[maxn]; 9 int dp[maxn]; 10 int main() 11 { 12 cin>>T; 13 while(T--) 14 { 15 int n; 16 cin>>n; 17 a[0]=0; 18 for(int i=1;i<=n;i++) 19 scanf("%d",&a[i]); 20 memset(dp,0,sizeof(dp)); 21 dp[1]=1; 22 for(int i=2;i<=n;i++){ 23 if(a[i]==a[i-1]) 24 dp[i]=dp[i-1]+1; 25 else{ 26 dp[i]=min((i-a[i]),dp[i-1]+1); 27 } 28 } 29 cout<<dp[n]<<endl; 30 } 31 return 0; 32 }
View Code

May Challenge 2017