0%
fds刷题记录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| #include <stdio.h> #include <stdlib.h>
int main() { int n,k,flag; char ch; scanf("%d",&n); getchar();
while(n--) { int a[3]= {0}; k=0; flag=1; while((ch=getchar())!='\n') { if(ch=='A') a[k]++; else if(ch=='P'&&k==0) k=1; else if(ch=='T'&&k==1) k=2; else flag=0; } if(flag&&k==2&&a[0]*a[1]==a[2]&&a[1]!=0) printf("YES\n"); else printf("NO\n"); } return 0; }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| class Solution { public: int maxProfit(vector<int>& prices) { int size=prices.size(); int dp[30005][2]={0},i; dp[0][1]=-prices[0]; for(i=1; i<size; i++) { dp[i][0] = (dp[i-1][0]>dp[i-1][1]+prices[i])?dp[i-1][0]:dp[i-1][1]+prices[i]; dp[i][1] = (dp[i-1][0]-prices[i]>dp[i-1][1])?dp[i-1][0]-prices[i]:dp[i-1][1]; } return dp[size-1][0]; } };
|
1 2 3 4 5 6 7 8 9 10
| class Solution { public: int singleNumber(vector<int>& nums) { int res=0; for(int i=0; i<nums.size(); i++) { res=res^nums[i]; } return res; } };
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| class Solution { public: bool isValidSudoku(vector<vector<char>>& board) { int line[9] = {0}; int column[9] = {0}; int block[9] = {0}; int shift = 0; for(int i = 0; i < 9; i++) { for(int j = 0; j <9; j++) { if(board[i][j] == '.') continue; shift = 1 << (board[i][j] - '0'); int k = (i / 3) * 3 + j / 3; if ((column[i] & shift) > 0 || (line[j] & shift) > 0 || (block[k] & shift) > 0) return false; column[i] |= shift; line[j] |= shift; block[k] |= shift; } } return true; } };
|